User:Krinkle/Scripts/PopCategoryDisplay.js

From Meta, a Wikimedia project coordination wiki

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * Pop Category Display
 * Created on June 24th, 2010
 *
 * @version 0.2.0 (2012-05-18)
 * @author Krinkle, 2010-2012
 * @source meta.wikimedia.org/wiki/User:Krinkle/Scripts/PopCategoryDisplay
 * @tracking [[File:Krinkle PopCategoryDisplay.js]]
 *
 * This script is released in the public domain by the authors.
 */
jQuery(document).ready(function () {
	"use strict";
	var pagesContainer, pagesLists, i, LIs, j, txt;

	// Check namespace
	if (mw.config.get('wgNamespaceNumber') !== 14) {
		return;
	}

	// Get pages-list
	pagesContainer = document.getElementById('mw-pages');
	if (!pagesContainer) {
		return;
	}

	// Get the individual list items
	pagesLists = pagesContainer.getElementsByTagName('ul');
	if (!pagesLists) {
		return;
	}

	// Loop through and pop the last /-part of the name and get rid of the rest
	for (i = 0; i < pagesLists.length; i += 1) {
		LIs = pagesLists[i].getElementsByTagName('li');
		for (j = 0; j < LIs.length; j += 1) {
			txt = LIs[j].getElementsByTagName('a')[0].innerHTML;
			LIs[j].getElementsByTagName('a')[0].innerHTML = txt.toString().split('/').pop();
		}
	}
});