MediaWiki:Common.js: различия между версиями
Перейти к навигации
Перейти к поиску
Xdarkes (обсуждение | вклад) |
Xdarkes (обсуждение | вклад) |
||
| Строка 1: | Строка 1: | ||
| + | <script> | ||
| + | (function () { | ||
| + | try { | ||
| + | if (localStorage.getItem('ligapedia-dark-mode') === '1') { | ||
| + | document.documentElement.classList.add('dark-mode'); | ||
| + | } | ||
| + | } catch (e) {} | ||
| + | })(); | ||
| + | </script> | ||
| + | |||
| + | |||
mw.loader.using(['mediawiki.util', 'mediawiki.storage']).done(function () { | mw.loader.using(['mediawiki.util', 'mediawiki.storage']).done(function () { | ||
var storageKey = 'ligapedia-dark-mode'; | var storageKey = 'ligapedia-dark-mode'; | ||
Версия 17:29, 12 августа 2026
<script>
(function () {
try {
if (localStorage.getItem('ligapedia-dark-mode') === '1') {
document.documentElement.classList.add('dark-mode');
}
} catch (e) {}
})();
</script>
mw.loader.using(['mediawiki.util', 'mediawiki.storage']).done(function () {
var storageKey = 'ligapedia-dark-mode';
var isDark = mw.storage.get(storageKey) === '1';
function setTheme(dark) {
if (dark) {
document.documentElement.classList.add('dark-mode');
mw.storage.set(storageKey, '1');
} else {
document.documentElement.classList.remove('dark-mode');
mw.storage.set(storageKey, '0');
}
isDark = dark;
}
if (isDark) {
document.documentElement.classList.add('dark-mode');
}
var link = mw.util.addPortletLink(
'p-personal',
'#',
'Тёмная тема',
'pt-dark-mode-toggle',
'Переключить тему'
);
if (link) {
$(link).on('click', function (e) {
e.preventDefault();
setTheme(!isDark);
$(this).text(isDark ? 'Светлая тема' : 'Тёмная тема');
});
$(link).text(isDark ? 'Светлая тема' : 'Тёмная тема');
}
});