MediaWiki:Common.js: различия между версиями
Внешний вид
Glamyr (обсуждение | вклад) Нет описания правки |
Glamyr (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
(function () { | mw.hook('wikipage.content').add(function () { | ||
const themes = { | const themes = { | ||
'theme-nanotrasen': { name: 'Nanotrasen TGUI', logo: '/images/5/58/Nanotrasen-logo.png' }, | 'theme-nanotrasen': { name: 'Nanotrasen TGUI', logo: '/images/5/58/Nanotrasen-logo.png' }, | ||
| Строка 34: | Строка 34: | ||
function injectSelector() { | function injectSelector() { | ||
if (document.getElementById('p-tg-theme')) return; | 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" style="margin-right: 8px; display: inline-block !important; vertical-align: middle !important;">'; | 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; position: relative;">'; | ||
selectHtml += '<input type="checkbox" id="p-tg-theme-dropdown-checkbox" role="button" aria-haspopup="true" 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="Выбрать тему фракции" 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 += '<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; padding: 0 !important; box-sizing: border-box !important;">'; | ||
selectHtml += '<span class="tg-custom-palette-icon" style="display: block !important; width: 20px !important; height: 20px !important;"></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; display: none; position: absolute; z-index: 1000;">'; | selectHtml += '<div class="vector-dropdown-content" style="padding: 8px; min-width: 180px; display: none; position: absolute; top: 100%; right: 0; 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;">'; | ||
| Строка 70: | Строка 70: | ||
} | } | ||
const checkExist = setInterval(function() { | |||
const userLinks = document.querySelector('.vector-user-links, .vector-header-end'); | |||
if (userLinks) { | |||
injectSelector(); | |||
clearInterval(checkExist); | |||
} | |||
}, 100); | |||
}); | |||
$(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) { | |||
e.preventDefault(); | |||
const chosenTheme = $(this).data('theme'); | |||
const classes = ['theme-stddark', 'theme-nanotrasen', 'theme-syndicate', 'theme-plasmafire', 'theme-clockcult', 'theme-bloodcult', 'theme-heretic', 'theme-default']; | |||
classes.forEach(id => document.body.classList.remove(id)); | |||
document.body.classList.remove('theme-active-dark'); | |||
document.body.classList.add(chosenTheme); | |||
if (chosenTheme !== 'theme-default') { | |||
document.body.classList.add('theme-active-dark'); | |||
} | |||
localStorage.setItem('mw-tg-theme', chosenTheme); | |||
const logos = { | |||
'theme-nanotrasen': '/images/5/58/Nanotrasen-logo.png', | |||
'theme-syndicate': '/images/c/ce/Syndicate-logo.png', | |||
}; | |||
const logoImg = document.querySelector('.mw-wiki-logo, .vector-header-container .mw-logo-img, .vector-logo-img'); | |||
if (logoImg) { | |||
if (logoImg.tagName === 'IMG') { logoImg.src = logos[chosenTheme]; } | |||
else { logoImg.style.backgroundImage = `url(${logos[chosenTheme]})`; } | |||
} | |||
$('.tg-theme-item').css({'font-weight': 'normal', 'color': ''}); | |||
$(this).css({'font-weight': 'bold', 'color': 'var(--accent)'}); | |||
$('#p-tg-theme-dropdown-checkbox').prop('checked', false).trigger('change'); | |||
}); | |||