function toggleTheme() { const body = document.body; const button = document.querySelector('.theme-toggle'); const isDark = body.classList.contains('dark-theme'); if (isDark) { body.classList.remove('dark-theme'); button.textContent = 'Включить светлую тему'; localStorage.setItem('theme', 'light'); } else { body.classList.add('dark-theme'); button.textContent = 'Включить темную тему'; localStorage.setItem('theme', 'dark'); } } function initTheme() { const savedTheme = localStorage.getItem('theme') || 'light'; const button = document.querySelector('.theme-toggle'); if (savedTheme === 'dark') { document.body.classList.add('dark-theme'); if (button) { button.textContent = 'Включить темную тему'; } } } document.addEventListener('DOMContentLoaded', initTheme);