мНет описания правки Метка: отменено |
мНет описания правки Метка: отменено |
||
Строка 15: | Строка 15: | ||
// Добавляем кнопку через jQuery | // Добавляем кнопку через jQuery | ||
mw.loader.using('jquery').then(function() { | mw.loader.using('jquery').then(function() { | ||
mw.util.addPortletLink( | |||
'p-tb', // Раздел "Инструменты" | |||
'#', | |||
'🌓 Тема', | |||
'theme-switcher', | |||
'Переключить тему', | |||
null, | |||
$('#pt-preferences').next() | |||
).on('click', function(e) { | |||
e.preventDefault(); | |||
toggleTheme(); | |||
}); | }); | ||
}); | }); |
Версия от 14:01, 1 апреля 2025
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
// Объявляем функцию глобально
window.toggleTheme = function() {
document.body.classList.toggle('dark-theme');
localStorage.setItem('theme', document.body.classList.contains('dark-theme') ? 'dark' : 'light');
};
// Загрузка сохраненной темы
document.addEventListener('DOMContentLoaded', function() {
const theme = localStorage.getItem('theme');
if (theme === 'dark') document.body.classList.add('dark-theme');
});
// Добавляем кнопку через jQuery
mw.loader.using('jquery').then(function() {
mw.util.addPortletLink(
'p-tb', // Раздел "Инструменты"
'#',
'🌓 Тема',
'theme-switcher',
'Переключить тему',
null,
$('#pt-preferences').next()
).on('click', function(e) {
e.preventDefault();
toggleTheme();
});
});