Jump to content

英文维基 | 中文维基 | 日文维基 | 草榴社区

User:Ais523/topcontrib.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.
// [[User:Ais523/topcontrib.js]]

// This script color-codes lines according to who has the top contribution for a page.
//<pre><nowiki>
$(document).ready(function () {
  if(mw.config.get('wgCanonicalSpecialPageName') === 'Contributions'
     &&location.href.indexOf("&ais523")==-1&&location.href.indexOf("?ais523")==-1)
     // the ais523 in the line above is meant to be ais523, not your username; it's
     // to avoid a clash with a couple of other scripts I've written. Feel free to
     // expand it to avoid clashes with other contribs-manipulating scripts, though.
  {
	var hash = { };
	$('ul.mw-contributions-list > li').each(function(index, item) {
		var $a = $(item).find('a.mw-contributions-title');
		var href = $a.attr('href');
		// get the page title
		var match = $a.hasClass('mw-redirect') ? href.match(/\/w\/index.php\?title=([^&]*)&/) : href.match(/\/wiki\/([^"]*)/);
		var title = match[1];
		// determine background color
		var topspanfound = $(item).find('span.mw-uctop').length > 0;
		var bg = topspanfound ? "#CCCCFF" : "#FFCCCC";
		if (hash[title] !== undefined) 
			bg = hash[title] == "#CCCCFF" ? "#CCFFFF" : "#FFFFCC"; 
		else
			hash[title] = bg;
		// set the background color
		var $span = $('<span></span>');
		$span.css('background-color', bg);
		
		$span.append($(item).contents());
		$(item).append($span);
	});
  }
});

//</nowiki></pre>
//[[Category:Wikipedia scripts]]