мНет описания правки Метка: отменено |
мНет описания правки Метка: отменено |
||
Строка 1: | Строка 1: | ||
window.toggleTheme = function() { | window.toggleTheme = function() { | ||
document.body.classList.toggle('dark-theme'); | document.body.classList.toggle('dark-theme'); | ||
Строка 5: | Строка 4: | ||
}; | }; | ||
document.addEventListener('DOMContentLoaded', function() { | document.addEventListener('DOMContentLoaded', function() { | ||
var savedTheme = localStorage.getItem('theme'); | var savedTheme = localStorage.getItem('theme'); | ||
if (savedTheme === 'dark') | if (savedTheme === 'dark') document.body.classList.add('dark-theme'); | ||
}); | }); | ||
mw.hook('citizen.load').add(function() { | mw.hook('citizen.load').add(function() { | ||
var button = document.createElement('button'); | var button = document.createElement('button'); | ||
button. | button.textContent = '🌓 Тема'; | ||
button.style. | button.style.cssText = 'margin: 0 10px; padding: 8px 12px; cursor: pointer;'; | ||
button.onclick = toggleTheme; | button.onclick = toggleTheme; | ||
var headerTools = document.querySelector('.citizen-header__tools'); | var headerTools = document.querySelector('.citizen-header__tools'); | ||
if (headerTools) { | if (headerTools) { | ||
headerTools.insertBefore(button, headerTools.firstChild); | headerTools.insertBefore(button, headerTools.firstChild); | ||
} | } | ||
}); | |||
try { | try { | ||
// Весь ваш код | // Весь ваш код |
Версия от 14:29, 1 апреля 2025
window.toggleTheme = function() {
document.body.classList.toggle('dark-theme');
localStorage.setItem('theme', document.body.classList.contains('dark-theme') ? 'dark' : 'light');
};
document.addEventListener('DOMContentLoaded', function() {
var savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') document.body.classList.add('dark-theme');
});
mw.hook('citizen.load').add(function() {
var button = document.createElement('button');
button.textContent = '🌓 Тема';
button.style.cssText = 'margin: 0 10px; padding: 8px 12px; cursor: pointer;';
button.onclick = toggleTheme;
var headerTools = document.querySelector('.citizen-header__tools');
if (headerTools) {
headerTools.insertBefore(button, headerTools.firstChild);
}
});
try {
// Весь ваш код
} catch (error) {
console.error('Ошибка в скрипте темы:', error);
}
});