User:Resolute/monobook.js

Source: 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.
importScript('User:Shubinator/DYKcheck.js'); //DYKcheck tool
importScript('User:Anomie/util.js');
importScript('User:Anomie/linkclassifier.js'); // Linkback: [[User:Anomie/linkclassifier.js]]

/*
	Wikicup Viewer
 
	TODO Indicate min. points required for wildcard spot.
*/
if (typeof(unsafeWindow) != 'undefined')
{
	addOnloadHook = unsafeWindow.addOnloadHook;
	console = unsafeWindow.console;
	mw = unsafeWindow.mw;
}
 
function wikicupSorter()
{
	if (mw.config.get('wgPageName') != 'Wikipedia:WikiCup') return false;
 
	mw.util.addCSS('.wikicup-failing td { background-color: #fee; }\
		.wikicup-passing td { background-color: #efe; }\
		.wikicup-self td { background-color: #ffe; }\
	');
 
	var topContestants = 2, topWildcards = 16; // Until April 28
	var score = $('.headerSort[abbr=Score]').click().click();
	var username = mw.config.get('wgUserName');
 
	// Self: #ffe, passing: #efe, failing: #fee
	score.each(function()
	{
		var contestantCount = 0;
 
		$(this).parent().parent().next().children().each(function()
		{
			var contestant = $(this);
			contestant.addClass('wikicup-contestant');
 
			if (contestant.text().match(username)) contestant.addClass('wikicup-self');
			if (contestantCount < topContestants) contestant.addClass('wikicup-passing'); // Passing
			else contestant.addClass('wikicup-failing'); // Failing
 
			contestantCount++;
		});
	});
 
	// Now do the wildcards
	var failingScores = [];
	$('.wikicup-failing').each(function()
	{
		failingScores.push([$(this), $(this).children(':last').text()]);
	});
 
	// Sort failing scores by score
	function sortFailingScores(a, b)
	{
		if (a[1] < b[1]) return 1;
		else if (a[1] == b[1]) return 0;
		else return -1;
	}
 
	failingScores.sort(sortFailingScores);
	var wildcards = failingScores.slice(0, topWildcards);
	for (var i = 0; i < wildcards.length; i++) wildcards[i][0].addClass('wikicup-passing');
}
 
addOnloadHook(wikicupSorter); // addOnloadHook necessary to allow table to be sortable first

mw.loader.load('//en.wikipedia.org/w/index.php?title=User%3APyrospirit%2Fmetadata.js&action=raw&ctype=text/javascript'); // [[User:Pyrospirit/metadata.js]]