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 to strip "Category:" prefix from links
     function stripCategoryPrefix(container) {
     function stripCategoryPrefix(container) {
         container.querySelectorAll('a').forEach(function(link) {
         container.querySelectorAll('a').forEach(function(link) {
            // Only process links to categories
             if (link.href.includes('/Category:') && link.textContent.startsWith('Category:')) {
             if (link.href.includes('/Category:') && link.textContent.startsWith('Category:')) {
                 link.textContent = link.textContent.replace(/^Category:/, '');
                 link.textContent = link.textContent.replace(/^Category:/, '');
Line 9: Line 10:
     }
     }


     // Hook into Minerva page rendering
     // Hook into Minerva page content rendering
     mw.hook('wikipage.content').add(function($content) {
     mw.hook('wikipage.content').add(function($content) {
         stripCategoryPrefix($content[0]);
         stripCategoryPrefix($content[0]);
     });
     });


     // Also run immediately for already loaded content
     // Run immediately for already loaded content
     stripCategoryPrefix(document);
     stripCategoryPrefix(document);
   
 
     // Hide "Category:" in page headers
     // Hide "Category:" namespace labels in headers
     const hideNamespace = () => {
     const hideNamespace = () => {
         document.querySelectorAll('.minerva-header .ns-category, .mw-page-title-namespace, .page-heading .ns-category')
         document.querySelectorAll(
            .forEach(el => el.style.display = 'none');
            '.minerva-header .ns-category, ' +
            '.mw-page-title-namespace, ' +
            '.page-heading .ns-category'
        ).forEach(el => el.style.display = 'none');
     };
     };
     hideNamespace();
     hideNamespace();
     const observer = new MutationObserver(hideNamespace);
 
    // Observe the body for dynamically added content (Minerva can re-render headers)
     const observer = new MutationObserver(function() {
        hideNamespace();
        stripCategoryPrefix(document);
    });
     observer.observe(document.body, { childList: true, subtree: true });
     observer.observe(document.body, { childList: true, subtree: true });
});
});

Revision as of 03:43, 9 October 2025

mw.loader.using('mediawiki.util').then(function () {

    // Function to strip "Category:" prefix from links
    function stripCategoryPrefix(container) {
        container.querySelectorAll('a').forEach(function(link) {
            if (link.href.includes('/Category:') && link.textContent.startsWith('Category:')) {
                link.textContent = link.textContent.replace(/^Category:/, '');
            }
        });
    }

    // Hook into Minerva page content rendering
    mw.hook('wikipage.content').add(function($content) {
        stripCategoryPrefix($content[0]);
    });

    // Run immediately for already loaded content
    stripCategoryPrefix(document);

    // Hide "Category:" namespace labels in headers
    const hideNamespace = () => {
        document.querySelectorAll(
            '.minerva-header .ns-category, ' +
            '.mw-page-title-namespace, ' +
            '.page-heading .ns-category'
        ).forEach(el => el.style.display = 'none');
    };

    hideNamespace();

    // Observe the body for dynamically added content (Minerva can re-render headers)
    const observer = new MutationObserver(function() {
        hideNamespace();
        stripCategoryPrefix(document);
    });
    observer.observe(document.body, { childList: true, subtree: true });

});