No edit summary
No edit summary
Line 1: Line 1:
mw.loader.using('mediawiki.util').then(function () {
// Only run for MinervaNeue
 
if ( mw.config.get('skin') === 'minerva' ) {
    // Function to strip "Category:" prefix from links
    mw.hook('wikipage.content').add(function($content) {
    function stripCategoryPrefix(container) {
        // Remove "Category:" prefix from all links inside content
         container.querySelectorAll('a').forEach(function(link) {
         $content.find('a').each(function() {
             if (link.href.includes('/Category:') && link.textContent.startsWith('Category:')) {
            var $link = $(this);
                 link.textContent = link.textContent.replace(/^Category:/, '');
             if ( $link.attr('href') && $link.attr('href').includes('/Category:') ) {
                 $link.text($link.text().replace(/^Category:/, ''));
             }
             }
         });
         });
     }
     });


     // Hook into Minerva page content rendering
     // Remove prefix from category page headers
     mw.hook('wikipage.content').add(function($content) {
     $(document).ready(function() {
         stripCategoryPrefix($content[0]);
         $('.minerva-header .ns-category, .page-heading .ns-category, .mw-page-title-namespace').hide();
     });
     });


     // Run immediately for already loaded content
     // Observe for dynamically injected content (e.g., forms/templates)
    stripCategoryPrefix(document);
     const observer = new MutationObserver(function(mutations) {
 
         mutations.forEach(function() {
    // Hide "Category:" namespace labels in headers
             $('.minerva-header .ns-category, .page-heading .ns-category, .mw-page-title-namespace').hide();
     const hideNamespace = () => {
             $('a').each(function() {
         document.querySelectorAll(
                var $link = $(this);
             '.minerva-header .ns-category, ' +
                if ($link.attr('href') && $link.attr('href').includes('/Category:')) {
            '.mw-page-title-namespace, ' +
                    $link.text($link.text().replace(/^Category:/, ''));
             '.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 });
     observer.observe(document.body, { childList: true, subtree: true });
 
}
});

Revision as of 03:45, 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:/, ''));
            }
        });
    });

    // Remove prefix from category page headers
    $(document).ready(function() {
        $('.minerva-header .ns-category, .page-heading .ns-category, .mw-page-title-namespace').hide();
    });

    // Observe for dynamically injected content (e.g., forms/templates)
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function() {
            $('.minerva-header .ns-category, .page-heading .ns-category, .mw-page-title-namespace').hide();
            $('a').each(function() {
                var $link = $(this);
                if ($link.attr('href') && $link.attr('href').includes('/Category:')) {
                    $link.text($link.text().replace(/^Category:/, ''));
                }
            });
        });
    });
    observer.observe(document.body, { childList: true, subtree: true });
}