Jump to content

User:Gary/custom long pages.js

From Wikipedia, the free encyclopedia
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".
*/

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

$(customLongPages);
function customLongPages()
{
	var jumpToNav = $('#jump-to-nav');
	if (mw.config.get('wgPageName') != 'Special:LongPages' || !jumpToNav.length) return false;
	
	var newNode = $('<p><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></p>');
	jumpToNav.after(newNode);
	if (location.href.indexOf('hide=lists') == -1) return false;
	
	var hiddenArticles = 0;
	$('.special').eq(0).children().each(function()
	{
		var article = $(this);
		
		if (article[0].nodeType != 1) return true;
		if (article.children().eq(1).text().indexOf('List of') == 0)
		{
			article.css('display', 'none');
			hiddenArticles++;
		}
	});
	
	$('.mw-spcontent').eq(0).children().first().children().first().append('<span id="hidden-articles"> (' + hiddenArticles + ' hidden' + ')</span>');
}