MediaWiki:Vector.js: различия между версиями
Aylong (обсуждение | вклад) Отмена правки 72137, сделанной Aylong (обсуждение) Метки: отмена отменено |
Aylong (обсуждение | вклад) Нет описания правки Метка: отменено |
||
| Строка 1: | Строка 1: | ||
function toggleTheme() { | |||
const body = document.querySelector('body'); | |||
if (body.classList.contains('dark')) { | |||
body.classList.remove('dark'); | |||
body.classList.add('light'); | |||
localStorage.setItem('theme', 'light'); | |||
} else { | |||
body.classList.remove('light'); | |||
body.classList.add('dark'); | |||
localStorage.setItem('theme', 'dark'); | |||
} | |||
} | |||
function getSavedTheme() { | |||
return localStorage.getItem('theme') || 'dark'; | |||
} | |||
function initTheme() { | |||
const savedTheme = getSavedTheme(); | |||
const body = document.querySelector('body'); | |||
body.classList.add(savedTheme); | |||
} | |||
function | function createThemeButton() { | ||
const personalElement = document.querySelector('#p-personal'); | |||
const themeButton = document.createElement('button'); | |||
themeButton.textContent = 'Сменить тему'; | |||
themeButton.addEventListener('click', toggleTheme); | |||
personalElement.parentNode.insertBefore(themeButton, personalElement); | |||
} | |||
document.addEventListener('DOMContentLoaded', function () { | |||
} | initTheme(); | ||
createThemeButton(); | |||
}); | |||
Версия от 17:20, 4 мая 2024
function toggleTheme() {
const body = document.querySelector('body');
if (body.classList.contains('dark')) {
body.classList.remove('dark');
body.classList.add('light');
localStorage.setItem('theme', 'light');
} else {
body.classList.remove('light');
body.classList.add('dark');
localStorage.setItem('theme', 'dark');
}
}
function getSavedTheme() {
return localStorage.getItem('theme') || 'dark';
}
function initTheme() {
const savedTheme = getSavedTheme();
const body = document.querySelector('body');
body.classList.add(savedTheme);
}
function createThemeButton() {
const personalElement = document.querySelector('#p-personal');
const themeButton = document.createElement('button');
themeButton.textContent = 'Сменить тему';
themeButton.addEventListener('click', toggleTheme);
personalElement.parentNode.insertBefore(themeButton, personalElement);
}
document.addEventListener('DOMContentLoaded', function () {
initTheme();
createThemeButton();
});