add advanced night theme
This commit is contained in:
@@ -317,18 +317,37 @@ window.onload = function () {
|
||||
});
|
||||
};
|
||||
|
||||
// Кнопка и иконка
|
||||
|
||||
const themeToggle = document.getElementById('theme-toggle');
|
||||
const themeIcon = document.getElementById('theme-icon');
|
||||
|
||||
// Обработчик клика
|
||||
themeToggle.addEventListener('click', () => {
|
||||
document.body.classList.toggle('dark-theme'); // Переключаем класс для темы
|
||||
|
||||
// Меняем иконку
|
||||
if (document.body.classList.contains('dark-theme')) {
|
||||
themeIcon.classList.replace('fa-sun', 'fa-moon');
|
||||
} else {
|
||||
const applySavedTheme = () => {
|
||||
const savedTheme = localStorage.getItem('theme');
|
||||
if (savedTheme === 'dark') {
|
||||
document.body.classList.add('dark-theme');
|
||||
themeIcon.classList.replace('fa-moon', 'fa-sun');
|
||||
} else {
|
||||
document.body.classList.remove('dark-theme');
|
||||
themeIcon.classList.replace('fa-sun', 'fa-moon');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
themeToggle.addEventListener('click', () => {
|
||||
document.body.classList.toggle('dark-theme');
|
||||
|
||||
|
||||
if (document.body.classList.contains('dark-theme')) {
|
||||
themeIcon.classList.replace('fa-moon', 'fa-sun');
|
||||
localStorage.setItem('theme', 'dark');
|
||||
} else {
|
||||
themeIcon.classList.replace('fa-sun', 'fa-moon');
|
||||
localStorage.setItem('theme', 'light');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
applySavedTheme();
|
||||
});
|
||||
Reference in New Issue
Block a user