Перейти к содержанию

MediaWiki:Common.js

Материал из MassMeta Wiki
Версия от 13:26, 13 июня 2026; Glamyr (обсуждение | вклад) (ненавижу js)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)

Замечание: Возможно, после публикации вам придётся очистить кэш своего браузера, чтобы увидеть изменения.

  • Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl+F5 или Ctrl+R (⌘+R на Mac)
  • Google Chrome: Нажмите Ctrl+Shift+R (⌘+Shift+R на Mac)
  • Edge: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl+F5
  • Opera: Нажмите Ctrl+F5.
(function () {
    const themes = {
        'theme-nanotrasen': { name: 'Nanotrasen TGUI', logo: '/images/nanotrasen_logo.png' },
        'theme-syndicate':  { name: 'Syndicate TGUI',  logo: '/images/syndicate_logo.png' },
        'theme-plasmafire': { name: 'Plasmafire' },
        'theme-clockcult':  { name: 'Clock Cult' },
        'theme-bloodcult':  { name: 'Blood Cult' },
        'theme-heretic':    { name: 'Heretic' },
        'theme-stddark':    { name: 'Standard Dark' },
        'theme-default':    { name: 'Standard Light' }
    };

    function applyTheme(themeId) {
        Object.keys(themes).forEach(id => document.body.classList.remove(id));
        
        if (themeId && themes[themeId]) {
            document.body.classList.add(themeId);
            localStorage.setItem('mw-tg-theme', themeId);
            
            const logoImg = document.querySelector('.mw-wiki-logo, .vector-header-container .mw-logo-img, .vector-logo-img');
            if (logoImg) {
                if (logoImg.tagName === 'IMG') {
                    logoImg.src = themes[themeId].logo;
                } else {
                    logoImg.style.backgroundImage = `url(${themes[themeId].logo})`;
                }
            }
        }
    }

    $(document).ready(function () {
        const activeTheme = localStorage.getItem('mw-tg-theme') || 'theme-default';
        applyTheme(activeTheme);

        let selectHtml = '<div id="tg-theme-selector-container" style="margin: 0 10px; display: inline-block; vertical-align: middle;">';
        selectHtml += '<select id="tg-theme-selector" style="background:#222; color:#fff; border:1px solid #444; padding:4px; border-radius:4px; font-size:12px; cursor:pointer;">';
        
        Object.keys(themes).forEach(id => {
            const selected = (id === activeTheme) ? 'selected' : '';
            selectHtml += `<option value="${id}" ${selected}> ${themes[id].name}</option>`;
        });
        
        selectHtml += '</select></div>';

        const personalTools = document.getElementById('p-personal') || document.querySelector('.vector-user-links');
        if (personalTools) {
            $(personalTools).prepend(selectHtml);
        }

        $('#tg-theme-selector').on('change', function () {
            applyTheme($(this).val());
        });
    });
})();