document.addEventListener('DOMContentLoaded', () => { const navHTML = ` `; const header = document.querySelector('header'); if (header) header.innerHTML += navHTML; // Показать/скрыть выход, проверив сессию fetch('/api/me') .then(r => r.json()) .then(data => { if (data.isAdmin) { document.getElementById('logoutLink').style.display = 'inline'; } }); document.addEventListener('click', (e) => { if (e.target.id === 'logoutLink') { e.preventDefault(); fetch('/api/logout', { method: 'POST' }) .then(() => window.location.href = '/login.html'); } }); });