User:Gary/mark edits after my own.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Gary/mark edits after my own. |
/*
MARK EDITS AFTER MY OWN
Description: Marks edits on contribution pages where the user's edit is not the most recent on that page.
Does not mark pages on your watchlist, since you are already notified of those.
*/
if (typeof(unsafeWindow) != 'undefined')
{
var console = unsafeWindow.console;
importStylesheet = unsafeWindow.importStylesheet;
mw = unsafeWindow.mw;
sajax_init_object = unsafeWindow.sajax_init_object;
}
function markEditsAfterMyOwn()
{
if (!mw.config.get('wgPageName').match('Special:Contributions')) return;
importStylesheet('User:Gary/highlighted link.css');
if ($('#contentSub').children().eq(0).text() == mw.config.get('wgUserName')) var isOwnUserContributions = true;
else var isOwnUserContributions = false;
// get watchlist items first so that they aren't marked as well, only for current user's contributions
if (isOwnUserContributions) $.get(mw.config.get('wgScriptPath') + '/api.php', { action: 'query', list: 'watchlist', wllimit: 500, format: 'json' }, markEditsAfterMyOwnWatchlist);
else markEditsAfterMyOwnMark('', false);
};
function markEditsAfterMyOwnWatchlist(obj)
{
var watchlist = obj['query']['watchlist'];
var pagesToIgnore = {};
for (var i = 0; i < watchlist.length; i++)
{
if (pagesToIgnore[watchlist[i]['title']]) pagesToIgnore[watchlist[i]['title']]++;
else pagesToIgnore[watchlist[i]['title']] = 1;
}
markEditsAfterMyOwnMark(pagesToIgnore, true);
}
function markEditsAfterMyOwnMark(pagesToIgnore, isOwnUserContributions)
{
if (isOwnUserContributions && $.isEmptyObject(pagesToIgnore)) $('#contentSub').append('. <span class="no-items-on-watchlist" style="color: #000; font-weight: bold;">Your watchlist is empty.</span>');
if (!pagesToIgnore) pagesToIgnore = {};
var markedPages = {};
$('#bodyContent ul:last').children().each(function()
{
var edit = $(this);
if (edit[0].nodeType == 3) return true;
var pageName = edit.children().eq(0).attr('title');
if ($('.mw-uctop', edit).length) markedPages[pageName] = 1;
else
{
if (markedPages[pageName]) markedPages[pageName]++;
else
{
// get the link to highlight it
var nodeNumber;
var children = edit.children();
var normalNode = 3;
var minorNode = 4;
var deletedNode = 2;
// Take the fourth A node. If not available, then always take the second.
var linkToHighlight = $('a:eq(3)', edit);
if (!linkToHighlight.length) linkToHighlight = $('a:eq(1)', edit);
// in most cases
// if (children.eq(normalNode).length && children.eq(normalNode)[0].nodeName == 'A') nodeNumber = normalNode;
// is a minor edit
// else if (children.eq(minorNode).length && children.eq(minorNode)[0].nodeName == 'A') nodeNumber = minorNode;
// a deleted edit
// else if (children.eq(deletedNode).length && children.eq(deletedNode)[0].nodeName == 'A') nodeNumber = deletedNode;
linkToHighlight.addClass(pagesToIgnore[pageName] ? 'highlighted-link-watched' : 'highlighted-link');
markedPages[pageName] = 1;
}
}
});
}
$(markEditsAfterMyOwn);