MediaWiki:Common.js: различия между версиями

Материал из Лигапедия Reborn
Перейти к навигации Перейти к поиску
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
(function () {
    var storageKey = 'ligapedia-dark-mode';
    if (localStorage.getItem(storageKey) === '1') {
        document.documentElement.classList.add('dark-mode');
        var style = document.createElement('style');
        style.textContent = `
            html.dark-mode,
            html.dark-mode body {
                background-color: #202231 !important;
            }
        `;
        if (document.head) {
            document.head.appendChild(style);
        } else {
            document.documentElement.appendChild(style);
        }
    }
})();
mw.loader.using(['mediawiki.util', 'mediawiki.storage']).done(function () {
mw.loader.using(['mediawiki.util', 'mediawiki.storage']).done(function () {


Строка 5: Строка 27:


     function setTheme(dark) {
     function setTheme(dark) {
         if (dark) {
         if (dark) {
             document.documentElement.classList.add('dark-mode');
             document.documentElement.classList.add('dark-mode');
Строка 36: Строка 59:
             setTheme(!isDark);
             setTheme(!isDark);


             $(this).text(isDark ? 'Светлая тема' : 'Тёмная тема');
             $(this).text(
                isDark ? 'Светлая тема' : 'Тёмная тема'
            );


         });
         });


         $(link).text(isDark ? 'Светлая тема' : 'Тёмная тема');
         $(link).text(
            isDark ? 'Светлая тема' : 'Тёмная тема'
        );
     }
     }


});
});

Версия от 17:23, 12 августа 2026

(function () {
    var storageKey = 'ligapedia-dark-mode';

    if (localStorage.getItem(storageKey) === '1') {
        document.documentElement.classList.add('dark-mode');

        var style = document.createElement('style');
        style.textContent = `
            html.dark-mode,
            html.dark-mode body {
                background-color: #202231 !important;
            }
        `;

        if (document.head) {
            document.head.appendChild(style);
        } else {
            document.documentElement.appendChild(style);
        }
    }
})();

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 ? 'Светлая тема' : 'Тёмная тема'
        );
    }

});