No edit summary
No edit summary
 
(2 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 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
    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 });
});

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:/, ''));
            }
        });
    });