MediaWiki:Minerva.js: Difference between revisions
(Created page with "→All JavaScript here will be loaded for users of the MinervaNeue skin: document.addEventListener('DOMContentLoaded', function() { // Remove "Category:" prefix from visible link text document.querySelectorAll('a[href*="/Category:"]').forEach(function(link) { if (link.textContent.startsWith('Category:')) { link.textContent = link.textContent.replace(/^Category:/, ''); } }); // Remove "Category:" from page title namespace la...") |
No edit summary |
||
| Line 1: | Line 1: | ||
/ | 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 | ||
const | 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 }); | |||
}); | }); | ||
Latest 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 });
});