Loading...

Loading...

`; navigator.clipboard.writeText(code); alert('Copied to clipboard!'); } // Modal controls function openModal() { document.getElementById('create-modal').classList.add('active'); } function closeModal() { document.getElementById('create-modal').classList.remove('active'); } // Create site form document.getElementById('create-form').addEventListener('submit', async (e) => { e.preventDefault(); const name = document.getElementById('site-name').value; const domain = document.getElementById('site-domain').value; try { const site = await api('POST', '/sites', { name, domain }); sites.push(site); closeModal(); document.getElementById('site-name').value = ''; document.getElementById('site-domain').value = ''; renderSitesList(); } catch (err) { alert('Error creating site: ' + err.message); } }); // Logout document.getElementById('logout-btn').addEventListener('click', async () => { await api('POST', '/auth/logout'); window.location.href = '/'; }); // Close modal on overlay click document.getElementById('create-modal').addEventListener('click', (e) => { if (e.target.classList.contains('modal-overlay')) { closeModal(); } }); // Hash change handler window.addEventListener('hashchange', () => { const hash = window.location.hash; if (hash === '' || hash === '#') { loadSites(); } else if (hash.startsWith('#site/')) { showSiteDetail(hash.slice(6)); } }); // Escape HTML function escapeHtml(str) { const div = document.createElement('div'); div.textContent = str; return div.innerHTML; } // Initialize on load init();