No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.using('mediawiki.util').then(function () {
// Only run for MinervaNeue
    function stripCategoryPrefix(container) {
if ( mw.config.get('skin') === 'minerva' ) {
         container.querySelectorAll('a').forEach(function(link) {
    mw.hook('wikipage.content').add(function($content) {
             // Only process links to categories
        // Remove "Category:" prefix from all links inside content
             if (link.href.includes('/Category:') && link.textContent.startsWith('Category:')) {
         $content.find('a').each(function() {
                 link.textContent = link.textContent.replace(/^Category:/, '');
             var $link = $(this);
             if ( $link.attr('href') && $link.attr('href').includes('/Category:') ) {
                 $link.text($link.text().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 });
});

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