Index (обсуждение | вклад) Нет описания правки |
мНет описания правки Метка: отменено |
||
Строка 2: | Строка 2: | ||
// console.log("Привет"); | // console.log("Привет"); | ||
// Объявляем функцию глобально | |||
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() { | |||
$(function() { | |||
const button = $('<button>') | |||
.text('🌓 Тема') | |||
.css({ | |||
position: 'fixed', | |||
bottom: '20px', | |||
right: '20px', | |||
zIndex: 1000, | |||
padding: '10px', | |||
cursor: 'pointer', | |||
background: '#fff', | |||
border: '1px solid #000' | |||
}) | |||
.on('click', toggleTheme); | |||
$('body').append(button); | |||
}); | |||
}); |
Версия от 13:54, 1 апреля 2025
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
// console.log("Привет");
// Объявляем функцию глобально
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() {
$(function() {
const button = $('<button>')
.text('🌓 Тема')
.css({
position: 'fixed',
bottom: '20px',
right: '20px',
zIndex: 1000,
padding: '10px',
cursor: 'pointer',
background: '#fff',
border: '1px solid #000'
})
.on('click', toggleTheme);
$('body').append(button);
});
});