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

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

Нет описания правки
Нет описания правки
 
(не показано 7 промежуточных версий этого же участника)
Строка 1: Строка 1:
mw.hook('wikipage.content').add(function () {
$(function () {
     const themes = {
     const classes = ['theme-stddark', 'theme-nanotrasen', 'theme-syndicate', 'theme-plasmafire', 'theme-clockcult', 'theme-bloodcult', 'theme-heretic', 'theme-default'];
        '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) {
     function applyTheme(themeId) {
         Object.keys(themes).forEach(id => document.body.classList.remove(id));
         classes.forEach(id => document.body.classList.remove(id));
         document.body.classList.remove('theme-active-dark');
         document.body.classList.remove('theme-active-dark');
          
          
         if (themeId && themes[themeId]) {
         if (themeId && classes.includes(themeId)) {
             document.body.classList.add(themeId);
             document.body.classList.add(themeId);
             if (themeId !== 'theme-default') {
             if (themeId !== 'theme-default') {
Строка 21: Строка 12:
             }
             }
             localStorage.setItem('mw-tg-theme', 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]; }
                else { logoImg.style.backgroundImage = `url(${themes[themeId]})`; }
            }
         }
         }
     }
     }
Строка 40: Строка 25:
         selectHtml += '<span class="tg-custom-palette-icon"></span>';
         selectHtml += '<span class="tg-custom-palette-icon"></span>';
         selectHtml += '</label>';
         selectHtml += '</label>';
         selectHtml += '<div class="vector-dropdown-content" style="padding: 8px; min-width: 180px; display: none; position: absolute; top: 110%; right: 0; z-index: 1000;">';
         selectHtml += '<div class="vector-dropdown-content" id="p-tg-dropdown-menu" style="padding: 8px; min-width: 180px; display: none; position: absolute; top: 110%; right: 0; z-index: 10000;">';
         selectHtml += '<ul class="vector-menu-content-list" style="margin: 0; padding: 0; list-style: none;">';
         selectHtml += '<ul class="vector-menu-content-list" style="margin: 0; padding: 0; list-style: none;">';


         const names = { 'theme-stddark': 'Standard Dark', 'theme-nanotrasen': 'Nanotrasen TGUI', 'theme-syndicate': 'Syndicate TGUI', 'theme-plasmafire': 'Plasmafire', 'theme-clockcult': 'Clock Cult', 'theme-bloodcult': 'Blood Cult', 'theme-heretic': 'Heretic', 'theme-default': 'Standard Light' };
         const names = { 'theme-stddark': 'Standard Dark', 'theme-nanotrasen': 'Nanotrasen TGUI', 'theme-syndicate': 'Syndicate TGUI', 'theme-plasmafire': 'Plasmafire', 'theme-clockcult': 'Clock Cult', 'theme-bloodcult': 'Blood Cult', 'theme-heretic': 'Heretic', 'theme-default': 'Standard Light' };
         Object.keys(themes).forEach(id => {
         classes.forEach(id => {
             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;">${names[id]}</a></li>`;
             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;">' + names[id] + '</a></li>';
         });
         });
         selectHtml += '</ul></div></div>';
         selectHtml += '</ul></div></div>';