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

мНет описания правки
мНет описания правки
Строка 1: Строка 1:
;(function ($, mw) {
    if (mw.config.get('wgPageName') !== 'Обсуждение_участника:Pok') {
        return;
    }
    var STORAGE_KEY = 'wiki-theme',
        $tools = $('#user-tools'),
        theme = null,
        $btn;
    function applyTheme(name) {
        document.body.classList.remove('wgl-theme-dark', 'wgl-theme-light');
        document.body.classList.add('wgl-theme-' + name);
        mw.hook('wgl.themeChanged').fire(name);
        try {
            localStorage.setItem(STORAGE_KEY, name);
        } catch (e) {
            console.warn('Не удалось сохранить тему в localStorage:', e);
        }
        updateButton(name);
    }
    function updateButton(current) {
        var label = current === 'dark'
            ? '☀️ Перейти на светлую'
            : '🌙 Перейти на тёмную';
        $btn.text(label);
    }
    function init() {
        try {
            theme = localStorage.getItem(STORAGE_KEY);
        } catch (e) {
            theme = null;
        }
        if (theme !== 'light' && theme !== 'dark') {
            theme = 'dark';
        }
        applyTheme(theme);
        if ($tools.length) {
            $btn = $('<button>', {
                id: 'theme-toggle-btn',
                css: {
                    marginLeft: '0.5em',
                    padding: '0.2em 0.6em',
                    cursor: 'pointer',
                    'background-color': 'transparent',
                    border: '1px solid #888',
                    'border-radius': '0.2em',
                    'font-size': '0.9em'
                }
            }).on('click', function (e) {
                e.preventDefault();
                var next = (theme === 'dark') ? 'light' : 'dark';
                theme = next;
                applyTheme(next);
            });
            $tools.append($btn);
        }
    }
    $(init);
})(jQuery, mediaWiki);
const IFRAME_CONFIG = {
const IFRAME_CONFIG = {
iframe1: {
iframe1: {