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 removeCategoryPrefixFromNode(node) {
         container.querySelectorAll('a').forEach(function(link) {
         // If the node itself is a link or contains links
             // Only process links to categories
        const links = node.querySelectorAll ? node.querySelectorAll('a') : [];
             if (link.href.includes('/Category:') && link.textContent.startsWith('Category:')) {
        links.forEach(function(link) {
             // Skip if already processed
             if (link.dataset.cleaned) return;
            if (link.href && link.href.includes('/Category:') && link.textContent.startsWith('Category:')) {
                 link.textContent = link.textContent.replace(/^Category:/, '');
                 link.textContent = link.textContent.replace(/^Category:/, '');
                link.dataset.cleaned = true;
             }
             }
         });
         });
        // Additionally, check if the node itself is a link
        if (node.nodeType === Node.ELEMENT_NODE && node.tagName === 'A' &&
            node.href.includes('/Category:') && node.textContent.startsWith('Category:')) {
            node.textContent = node.textContent.replace(/^Category:/, '');
            node.dataset.cleaned = true;
        }
    }
    function cleanCategoryLinks(root = document) {
        removeCategoryPrefixFromNode(root);
        if (root.querySelectorAll) {
            root.querySelectorAll('a[href*="/Category:"]').forEach(removeCategoryPrefixFromNode);
        }
     }
     }


     // Initial clean
     // Hook into Minerva page rendering
     cleanCategoryLinks();
     mw.hook('wikipage.content').add(function($content) {
 
        stripCategoryPrefix($content[0]);
    // Observe the body for dynamically added content
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            mutation.addedNodes.forEach(cleanCategoryLinks);
        });
     });
     });


     observer.observe(document.body, { childList: true, subtree: true });
     // 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);
    // Observe headers too
     observer.observe(document.body, { childList: true, subtree: true });
     const headerObserver = new MutationObserver(hideNamespace);
     headerObserver.observe(document.body, { childList: true, subtree: true });
 
});
});

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 });
});