Jump to content

User:Gary/custom long pages.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gary (talk | contribs) at 21:14, 11 June 2010 (creating). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
	CUSTOM LONG PAGES
	Description: Adds options for [[Special:LongPages]], such as the ability to hide articles that begin with "List of".
	Link: [[User:Gary King/custom long pages.js]]
*/

if (typeof(unsafeWindow) != 'undefined')
{
	wgPageName = unsafeWindow.wgPageName;
}

function customLongPages()
{
	jumpToNav = document.getElementById('jump-to-nav');
	
	if (wgPageName != 'Special:LongPages' || !jumpToNav)
		return;
	
	newNode = document.createElement('p');
	newNode.innerHTML = '<b>Options:</b> <a href="' + location.href.replace('hide=lists', '') + '">Show</a> / <a href="' + location.href + (location.href.indexOf('?') != -1 ? '&hide=lists' : '?hide=lists') + '">hide lists</a>';
	
	jumpToNav.parentNode.insertBefore(newNode, jumpToNav.nextSibling);
	
	if (location.href.indexOf('hide=lists') == -1)
		return;
	
	articles = document.getElementsByClassName('special')[0].childNodes;
	hiddenArticles = 0;
	
	for (var i = 0; i < articles.length; i++)
	{
		if (articles[i].nodeType != 1)
			continue;
		
		if (articles[i].childNodes[3].firstChild.nodeValue.indexOf('List of') == 0)
		{
			articles[i].style.display = 'none';
			hiddenArticles++;
		}
	}
	
	showingBelow = document.getElementsByClassName('mw-spcontent')[0];
	hiddenArticlesNode = document.createTextNode(' (' + hiddenArticles + ' hidden' + ')');
	showingBelow.childNodes[0].childNodes[1].appendChild(hiddenArticlesNode);
}

if (typeof(unsafeWindow) == 'undefined')
	addOnloadHook(customLongPages);
else
	customLongPages();