MediaWiki:Common.js

From Rest of What I Know
Revision as of 07:14, 22 September 2025 by Roshan (talk | contribs) (Also do not display Template:BlogPreload)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Reverse sorting for Category:Blog and hide Template:BlogPreload
$(document).ready(function() {
    if (mw.config.get('wgCanonicalNamespace') === 'Category' && 
        mw.config.get('wgTitle') === 'Blog') {
        
        var $categoryList = $('#mw-pages');
        if ($categoryList.length) {
            var $items = $categoryList.find('li');
            
            // Filter out Template:BlogPreload from display
            $items = $items.filter(function() {
                var linkText = $(this).find('a').first().text();
                return linkText !== 'Template:BlogPreload';
            });
            
            // Sort remaining items in reverse order
            $items.detach().sort(function(a, b) {
                return $(b).text().localeCompare($(a).text());
            });
            
            // Replace the category list with filtered, sorted items
            $categoryList.empty().append($items);
        }
    }
});