User:Erutuon/scripts/hideUnwantedCategories.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

/*
	Hides categories in the list at [[Special:WantedCategories]]
	if they are crossed out.
*/

$(function () {
	var fullPageName = mw.config.get("wgPageName");
	if (!(fullPageName === "Special:WantedCategories"
	|| fullPageName === "Special:WantedTemplates"))
		return;
	
	mw.loader.using("oojs-ui").done(function () {
		var toHide;
		var hideText, showText;
		if (fullPageName === "Special:WantedCategories") {
			toHide = $("ol.special li").has("del");
			hideText = "Hide crossed-out entries", showText = "Show crossed-out entries";
		} else if (fullPageName === "Special:WantedTemplates") {
			toHide = $("ol.special li").filter(function (index, listItem) {
		    	var templateLink = listItem.querySelector("a");
				return templateLink && /^Template:tracking/.test(templateLink.textContent);
			});
			hideText = "Hide tracking templates", showText = "Show tracking templates";
		}
		toHide.hide();
		
		var hidden = true;
		var button = new OO.ui.ButtonWidget({
			label: showText,
		});
		
		$("ol.special").before(button.$element);
		
		button.$element.click(function () {
			hidden = !hidden;
			toHide.toggle();
			button.setLabel(hidden ? showText : hideText);
		});
	});
});