MediaWiki:Common.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* 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 });
})();