MediaWiki:Common:js
// Объявляем функцию глобально window.toggleTheme = function() {
const body = document.body;
body.classList.toggle('dark-theme');
localStorage.setItem('theme', body.classList.contains('dark-theme') ? 'dark' : 'light');
};
// Загрузка сохраненной темы document.addEventListener('DOMContentLoaded', function() {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') document.body.classList.add('dark-theme');
});
// Добавляем кнопку в верхнюю панель $(function() {
const button = $('<button>')
.text('🌓 Тема')
.on('click', toggleTheme)
.css({
margin: '0 10px',
padding: '5px 10px',
cursor: 'pointer'
});
$('#mw-header-navbar').prepend(button);
});