MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
mw.loader.using('mediawiki.util').then(function () { | mw.loader.using('mediawiki.util').then(function () { | ||
function stripCategoryPrefix(container) { | |||
function | container.querySelectorAll('a').forEach(function(link) { | ||
// Only process links to categories | |||
if (link.href.includes('/Category:') && link.textContent.startsWith('Category:')) { | |||
// | |||
if ( | |||
link.textContent = link.textContent.replace(/^Category:/, ''); | link.textContent = link.textContent.replace(/^Category:/, ''); | ||
} | } | ||
}); | }); | ||
} | } | ||
// | // Hook into Minerva page rendering | ||
mw.hook('wikipage.content').add(function($content) { | |||
stripCategoryPrefix($content[0]); | |||
}); | }); | ||
// Also run immediately for already loaded content | |||
stripCategoryPrefix(document); | |||
// Hide "Category:" in headers | |||
// Hide "Category:" in page headers | |||
const hideNamespace = () => { | const hideNamespace = () => { | ||
document.querySelectorAll('.minerva-header .ns-category, .mw-page-title-namespace, .page-heading .ns-category') | document.querySelectorAll('.minerva-header .ns-category, .mw-page-title-namespace, .page-heading .ns-category') | ||
| Line 46: | Line 23: | ||
}; | }; | ||
hideNamespace(); | hideNamespace(); | ||
const observer = new MutationObserver(hideNamespace); | |||
observer.observe(document.body, { childList: true, subtree: true }); | |||
const | |||
}); | }); | ||
Revision as of 03:42, 9 October 2025
mw.loader.using('mediawiki.util').then(function () {
function stripCategoryPrefix(container) {
container.querySelectorAll('a').forEach(function(link) {
// Only process links to categories
if (link.href.includes('/Category:') && link.textContent.startsWith('Category:')) {
link.textContent = link.textContent.replace(/^Category:/, '');
}
});
}
// Hook into Minerva page rendering
mw.hook('wikipage.content').add(function($content) {
stripCategoryPrefix($content[0]);
});
// Also run immediately for already loaded content
stripCategoryPrefix(document);
// Hide "Category:" in page headers
const hideNamespace = () => {
document.querySelectorAll('.minerva-header .ns-category, .mw-page-title-namespace, .page-heading .ns-category')
.forEach(el => el.style.display = 'none');
};
hideNamespace();
const observer = new MutationObserver(hideNamespace);
observer.observe(document.body, { childList: true, subtree: true });
});