// Функция переключения темы function toggleTheme() {
const body = document.body; body.classList.toggle('dark-theme'); // Сохранение выбора в localStorage const isDark = body.classList.contains('dark-theme'); localStorage.setItem('theme', isDark ? 'dark' : 'light');
}
// Загрузка сохраненной темы при открытии страницы document.addEventListener('DOMContentLoaded', function() {
const savedTheme = localStorage.getItem('theme'); if (savedTheme === 'dark') { document.body.classList.add('dark-theme'); }
});
// Добавление кнопки переключения темы $(function() {
const button = $('<button>') .text('🌓 Сменить тему') .on('click', toggleTheme) .css({ position: 'fixed', bottom: '20px', right: '20px', zIndex: '1000', padding: '10px', cursor: 'pointer' });
$('body').append(button);
});