const API = location.origin; async function doLogin() { const pwd = document.getElementById('pwdInput').value; if (!pwd) return; try { const res = await fetch(`${API}/api/stats`, { headers: { 'X-Admin-Token': pwd } }); if (res.ok) { sessionStorage.setItem('adminToken', pwd); location.href = 'dashboard.html'; } else { document.getElementById('loginErr').style.display = 'block'; } } catch { document.getElementById('loginErr').style.display = 'block'; } } document.getElementById('pwdInput').addEventListener('keydown', e => { if (e.key === 'Enter') doLogin(); }); document.querySelector('.login button').addEventListener('click', doLogin);