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

MediaWiki:Common.js

Материал из MassMeta Wiki

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

  • 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/5/58/Nanotrasen-logo.png' },
        'theme-syndicate':  { name: 'Syndicate TGUI',  logo: mw.util.getUrl('Special:Redirect/file/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));
        document.body.classList.remove('theme-active-dark');
        
        if (themeId && themes[themeId]) {
            document.body.classList.add(themeId);
            if (themeId !== 'theme-default') {
                document.body.classList.add('theme-active-dark');
            }
            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-stddark';
        applyTheme(activeTheme);

        let selectHtml = '<div id="p-tg-theme" class="vector-menu vector-dropdown vector-user-menu-logged-in vector-has-collapsible-items" style="margin-right: 8px;">';
        selectHtml += '<input type="checkbox" id="p-tg-theme-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-tg-theme" class="vector-dropdown-checkbox">';
        selectHtml += '<label id="p-tg-theme-dropdown-label" for="p-tg-theme-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--weight-quiet cdx-button--icon-only" aria-label="Смена темы" title="Выбрать тему фракции">';
        selectHtml += '<span class="vector-icon tg-custom-palette-icon"></span>';
        selectHtml += '</label>';
        selectHtml += '<div class="vector-dropdown-content" style="padding: 8px; min-width: 180px;">';
        selectHtml += '<ul class="vector-menu-content-list" style="margin: 0; padding: 0; list-style: none;">';

        Object.keys(themes).forEach(id => {
            const isSelected = id === activeTheme ? 'font-weight: bold; color: var(--accent) !important;' : '';
            selectHtml += `<li style="margin: 4px 0;"><a href="#" class="tg-theme-item" data-theme="${id}" style="display: block; padding: 6px 8px; border-radius: 4px; text-decoration: none; ${isSelected}">${themes[id].name}</a></li>`;
        });

        selectHtml += '</ul></div></div>';

        const userLinks = document.querySelector('.vector-user-links');
        if (userLinks) {
            const userMenu = document.getElementById('p-personal-more') || document.getElementById('p-userlinks');
            if (userMenu) {
                $(userMenu).before(selectHtml);
            } else {
                $(userLinks).prepend(selectHtml);
            }
        }

        $(document).on('click', '.tg-theme-item', function (e) {
            e.preventDefault();
            const chosenTheme = $(this).data('theme');
            applyTheme(chosenTheme);
            
            $('.tg-theme-item').css({'font-weight': 'normal', 'color': ''});
            $(this).css({'font-weight': 'bold', 'color': 'var(--accent)'});
            
            document.getElementById('p-tg-theme-dropdown-checkbox').checked = false;
        });
    });
})();