MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary Tag: Manual revert |
No edit summary |
||
| 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 }); | ||
})(); | |||
// Doom Archives header: inject above Vector 2022 left menu (robust) | |||
(function () { | |||
const HEADER_CLASS = 'doom-archives-header'; | |||
function findMenuRoot() { | |||
// Most reliable targets for Vector 2022 pinned menu | |||
return ( | |||
document.querySelector('#vector-main-menu-pinned-container nav.vector-main-menu') || | |||
document.querySelector('nav.vector-main-menu') || | |||
document.querySelector('nav.vector-main-menu-landmark nav') || | |||
document.querySelector('#mw-panel') // legacy fallback | |||
); | |||
} | |||
function addHeader() { | |||
const root = findMenuRoot(); | |||
if (!root) return; | |||
// Prefer adding inside the menu root at the very top | |||
if (root.querySelector('.' + HEADER_CLASS)) return; | |||
const header = document.createElement('div'); | |||
header.className = HEADER_CLASS; | |||
header.textContent = 'DOOM ARCHIVES'; | |||
// Insert as the first child of the menu root | |||
root.insertBefore(header, root.firstChild); | |||
} | |||
// Run early + on load | |||
addHeader(); | |||
window.addEventListener('load', addHeader); | |||
// Keep it there even if Vector re-renders the menu | |||
const obs = new MutationObserver(() => addHeader()); | |||
obs.observe(document.documentElement, { childList: true, subtree: true }); | |||
})(); | })(); | ||
Revision as of 16:12, 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 });
})();
// Doom Archives header: inject above Vector 2022 left menu (robust)
(function () {
const HEADER_CLASS = 'doom-archives-header';
function findMenuRoot() {
// Most reliable targets for Vector 2022 pinned menu
return (
document.querySelector('#vector-main-menu-pinned-container nav.vector-main-menu') ||
document.querySelector('nav.vector-main-menu') ||
document.querySelector('nav.vector-main-menu-landmark nav') ||
document.querySelector('#mw-panel') // legacy fallback
);
}
function addHeader() {
const root = findMenuRoot();
if (!root) return;
// Prefer adding inside the menu root at the very top
if (root.querySelector('.' + HEADER_CLASS)) return;
const header = document.createElement('div');
header.className = HEADER_CLASS;
header.textContent = 'DOOM ARCHIVES';
// Insert as the first child of the menu root
root.insertBefore(header, root.firstChild);
}
// Run early + on load
addHeader();
window.addEventListener('load', addHeader);
// Keep it there even if Vector re-renders the menu
const obs = new MutationObserver(() => addHeader());
obs.observe(document.documentElement, { childList: true, subtree: true });
})();