мНет описания правки |
мНет описания правки |
||
Строка 1: | Строка 1: | ||
// | // Объявляем функцию глобально | ||
function | 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() { | 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); | |||
}); | }); |
Версия от 13:37, 1 апреля 2025
// Объявляем функцию глобально 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);
});