MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary Tag: Reverted |
||
| Line 40: | Line 40: | ||
const obs = new MutationObserver(() => killMainMenuText()); | const obs = new MutationObserver(() => killMainMenuText()); | ||
obs.observe(document.documentElement, { childList: true, subtree: true }); | obs.observe(document.documentElement, { childList: true, subtree: true }); | ||
})(); | |||
// Insert a Doom Archives header above the left menu (works regardless of markup) | |||
(function () { | |||
function addHeader() { | |||
const menu = | |||
document.querySelector('#vector-main-menu-pinned-container nav.vector-main-menu .vector-menu-content') || | |||
document.querySelector('nav.vector-main-menu .vector-menu-content') || | |||
document.querySelector('#mw-panel .vector-menu-content'); | |||
if (!menu) return; | |||
if (menu.querySelector('.doom-archives-header')) return; | |||
const header = document.createElement('div'); | |||
header.className = 'doom-archives-header'; | |||
header.textContent = 'DOOM ARCHIVES'; | |||
menu.prepend(header); | |||
} | |||
addHeader(); | |||
window.addEventListener('load', addHeader); | |||
setTimeout(addHeader, 250); | |||
})(); | })(); | ||
Revision as of 16:10, 24 December 2025
/* Any JavaScript here will be loaded for all users on every page load. */
// Vector 2022: pin main menu for logged-out users on desktop
if (!mw.config.get('wgUserName') && window.matchMedia('(min-width: 1120px)').matches) {
const observer = new MutationObserver((_, obs) => {
if (document.documentElement.classList.contains('vector-animations-ready')) {
const pin = document.querySelector('[data-event-name="pinnable-header.vector-main-menu.pin"]');
if (pin) pin.click();
obs.disconnect();
}
});
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
}
// Remove "Main menu" headings/labels injected by Vector/Vector 2022 (works across variants)
(function () {
function killMainMenuText(root = document) {
// Look for common heading/label elements
const candidates = root.querySelectorAll(
'#vector-main-menu, #vector-main-menu-pinned-container, #mw-panel, nav.vector-main-menu, #vector-main-menu-dropdown'
);
candidates.forEach(container => {
// Remove elements whose visible text is exactly "Main menu"
container.querySelectorAll('*').forEach(el => {
const txt = (el.textContent || '').trim();
if (txt === 'Main menu') {
el.style.display = 'none';
}
// Also catch the longer hint text variants
if (txt.toLowerCase().includes('main menu has moved here')) {
el.style.display = 'none';
}
});
});
}
// Run now, on load, and after Vector finishes UI init
killMainMenuText();
window.addEventListener('load', () => killMainMenuText());
const obs = new MutationObserver(() => killMainMenuText());
obs.observe(document.documentElement, { childList: true, subtree: true });
})();
// Insert a Doom Archives header above the left menu (works regardless of markup)
(function () {
function addHeader() {
const menu =
document.querySelector('#vector-main-menu-pinned-container nav.vector-main-menu .vector-menu-content') ||
document.querySelector('nav.vector-main-menu .vector-menu-content') ||
document.querySelector('#mw-panel .vector-menu-content');
if (!menu) return;
if (menu.querySelector('.doom-archives-header')) return;
const header = document.createElement('div');
header.className = 'doom-archives-header';
header.textContent = 'DOOM ARCHIVES';
menu.prepend(header);
}
addHeader();
window.addEventListener('load', addHeader);
setTimeout(addHeader, 250);
})();