No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.using('mediawiki.util').then(function () {
// Only run for MinervaNeue
 
if ( mw.config.get('skin') === 'minerva' ) {
     function removeCategoryPrefixFromNode(node) {
     mw.hook('wikipage.content').add(function($content) {
         // If the node itself is a link or contains links
         // Remove "Category:" prefix from all links inside content
         const links = node.querySelectorAll ? node.querySelectorAll('a') : [];
         $content.find('a').each(function() {
        links.forEach(function(link) {
             var $link = $(this);
             // Skip if already processed
             if ( $link.attr('href') && $link.attr('href').includes('/Category:') ) {
            if (link.dataset.cleaned) return;
                 $link.text($link.text().replace(/^Category:/, ''));
             if (link.href && link.href.includes('/Category:') && link.textContent.startsWith('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
    cleanCategoryLinks();
    // 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 });
    // Hide "Category:" 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 headers too
    const headerObserver = new MutationObserver(hideNamespace);
    headerObserver.observe(document.body, { childList: true, subtree: true });
});

Latest revision as of 14:24, 9 October 2025

// Only run for MinervaNeue
if ( mw.config.get('skin') === 'minerva' ) {
    mw.hook('wikipage.content').add(function($content) {
        // Remove "Category:" prefix from all links inside content
        $content.find('a').each(function() {
            var $link = $(this);
            if ( $link.attr('href') && $link.attr('href').includes('/Category:') ) {
                $link.text($link.text().replace(/^Category:/, ''));
            }
        });
    });