MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 11: | Line 11: | ||
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] }); | 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 }); | |||
})(); | |||
Revision as of 15:56, 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 });
})();