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