Jump to content

User:Gary/mark unviewed watchlist items.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.
/*
	MARK UNVIEWED WATCHLIST ITEMS
	Description: On the Watchlist, marks unviewed diffs with red text.
		Only tested with Enhanced Recent Changes enabled.
*/

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

function markUnviewedWatchlistItems()
{
	if (mw.config.get('wgCanonicalSpecialPageName') != 'Watchlist') return false;

	mw.util.addCSS('a.watchlist-diff { color: red; }');
	mw.util.addCSS('a.watchlist-diff:visited { color: #551A8B; }');

	// loop through each day
	$('#bodyContent h4').each(function()
	{
		var day = $(this);
		
		// loop through each page
		$('table', day.next()).each(function()
		{
			var table = $(this);
			
			// check that this is really a diff link by determing the link's text; checks if link is actually a link, and if it contains "diff" or "changes" or "hist" or "history"
			var diffLink = table.children().eq(0).children().eq(0).children().eq(-1).children().eq(1);
			if (diffLink.length && diffLink[0].nodeName == 'A' && (diffLink.text() == 'diff' || diffLink.text().match('changes') || diffLink.text() == 'hist' || diffLink.text() == 'history')) diffLink.addClass('watchlist-diff');
		});
	});
}

$(markUnviewedWatchlistItems);