User:Dantheox/watchlistdiff.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:Dantheox/watchlistdiff. |
//<pre>
function instrumentWLgroup(g) {
var edits = g.getElementsByTagName('a');
var re = new RegExp(/curid=\d+&oldid=(\d+)/);
var pre = new RegExp(/^(.*?\/w\/index.php\?title=[^&]+)/);
var grp = g.id;
var ids = new Array();
var pageLink = null;
for (var i=0; i<edits.length; i++) {
var m = re.exec(edits[i].href);
if (m != null && edits[i].href.match(/&diff=/) == null) {
// This is a link to a particular revision being listed on the watchlist
ids.push(m[1]);
}
m = pre.exec(edits[i].href);
if (m != null && edits[i].href.match(/&diff=/)) {
pageLink = m[1];
}
}
for (var i=0; i<g.childNodes.length; i++) {
var n = g.childNodes[i];
if (n.nodeType==3 && n.textContent==") . . ") {
var revID = ids.shift();
var newNode = document.createElement('span');
var rA = g.id + "A";
var rB = g.id + "B";
var doDiff = "location.href=\"" + pageLink + "&diff=\"+" + rB + "+\"&oldid=\"+" + rA + "; ";
newNode.innerHTML = ") " +
"<input type=radio name=" + g.id + "A onClick='" + rA + "=" + revID + "; if ("+rB+") { " + doDiff + " } '/>" +
"<input type=radio name=" + g.id + "B onClick='" + rB + "=" + revID + "; if ("+rA+") { " + doDiff + " } '/> ";
g.replaceChild(newNode, n);
}
}
}
function watchListGroup() {
if (window.location.href.indexOf("Special:Watchlist") != -1) {
var items=document.getElementById('bodyContent').getElementsByTagName('div');
for (var i=0; i<items.length; i++) {
if (items[i].id.match(/RCI\d+/)) {
instrumentWLgroup(items[i]);
}
}
}
}
addOnloadHook(watchListGroup);
//</pre>