No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.using('mediawiki.util').then(function () {
// Only run for MinervaNeue
    function cleanCategoryLinks(root = document) {
if ( mw.config.get('skin') === 'minerva' ) {
         root.querySelectorAll('a[href*="/Category:"]').forEach(function(link) {
    mw.hook('wikipage.content').add(function($content) {
             if (link.dataset.cleaned) return; // avoid double-processing
        // Remove "Category:" prefix from all links inside content
             if (link.textContent.startsWith('Category:')) {
         $content.find('a').each(function() {
                 link.textContent = link.textContent.replace(/^Category:/, '');
             var $link = $(this);
                link.dataset.cleaned = true;
             if ( $link.attr('href') && $link.attr('href').includes('/Category:') ) {
                 $link.text($link.text().replace(/^Category:/, ''));
             }
             }
        });
    }
    // Initial run
    cleanCategoryLinks();
    // Observe the page for dynamically added content (MinervaNeue does this)
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            mutation.addedNodes.forEach(function(node) {
                if (node.nodeType === Node.ELEMENT_NODE) {
                    cleanCategoryLinks(node);
                }
            });
         });
         });
     });
     });
    observer.observe(document.body, { childList: true, subtree: true });
    // Hide "Category:" in page headers / namespace labels
    const hideNamespace = () => {
        document.querySelectorAll('.minerva-header .ns-category, .mw-page-title-namespace, .page-heading .ns-category')
                .forEach(el => el.style.display = 'none');
    };
    hideNamespace();
    // Also observe for header changes
    const headerObserver = new MutationObserver(hideNamespace);
    const header = document.querySelector('body');
    if (header) headerObserver.observe(header, { 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:/, ''));
            }
        });
    });