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

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

Нет описания правки
Нет описания правки
Строка 33: Строка 33:
     }
     }


     $(document).ready(function () {
     function injectSelector() {
        if (document.getElementById('p-tg-theme')) return; // Если уже добавлен, выходим
 
         const activeTheme = localStorage.getItem('mw-tg-theme') || 'theme-stddark';
         const activeTheme = localStorage.getItem('mw-tg-theme') || 'theme-stddark';
         applyTheme(activeTheme);
         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;">';
         let selectHtml = '<div id="p-tg-theme" class="vector-menu vector-dropdown vector-user-menu-logged-in" style="margin-right: 8px; display: inline-block !important; vertical-align: middle !important;">';
         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 += '<input type="checkbox" id="p-tg-theme-dropdown-checkbox" role="button" aria-haspopup="true" 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 += '<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="Выбрать тему фракции" style="display: flex !important; width: 32px !important; height: 32px !important; align-items: center; justify-content: center; border: 1px solid var(--border-color, #444) !important; background: var(--bg-input, #222) !important; cursor: pointer;">';
         selectHtml += '<span class="vector-icon tg-custom-palette-icon"></span>';
         selectHtml += '<span class="tg-custom-palette-icon" style="display: block !important; width: 20px !important; height: 20px !important;"></span>';
         selectHtml += '</label>';
         selectHtml += '</label>';
         selectHtml += '<div class="vector-dropdown-content" style="padding: 8px; min-width: 180px;">';
         selectHtml += '<div class="vector-dropdown-content" style="padding: 8px; min-width: 180px; display: none; position: absolute; z-index: 1000;">';
         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;">';


Строка 52: Строка 54:
         selectHtml += '</ul></div></div>';
         selectHtml += '</ul></div></div>';


         const userLinks = document.querySelector('.vector-user-links');
         const targets = [
        if (userLinks) {
            document.querySelector('.vector-user-links-main'),
             const userMenu = document.getElementById('p-personal-more') || document.getElementById('p-userlinks');
             document.getElementById('p-personal-more'),
             if (userMenu) {
            document.getElementById('p-userlinks'),
                $(userMenu).before(selectHtml);
             document.querySelector('.vector-user-links'),
             } else {
            document.querySelector('.vector-header-end')
                 $(userLinks).prepend(selectHtml);
        ];
 
        for (let target of targets) {
             if (target) {
                 $(target).before(selectHtml);
                break;
             }
             }
         }
         }
    }
    $(document).ready(injectSelector);
    $(window).on('load', injectSelector);
    $(document).on('change', '#p-tg-theme-dropdown-checkbox', function() {
        const content = $(this).siblings('.vector-dropdown-content');
        if (this.checked) {
            content.css('display', 'block');
        } else {
            content.css('display', 'none');
        }
    });


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