User:Animum/Sandbox
Appearance
if(wgCanonicalSpecialPageName == "Contributions" && document.title.indexOf("for") != -1 && wgEnableAPI) {
var li_list = document.evaluate('//div[@id="bodyContent"]//ul/li[contains(span[@class="mw-uctop"], "(top)")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); //Lists all of the contributions that are the most recent edits on a page.
for(i=0;i<li_list.snapshotLength;i++) {
var li = li_list.snapshotItem(i);
var href = document.evaluate('a[1]/@href', li, null, XPathResult.STRING_TYPE, null).stringValue;
var oldid = href.split("&oldid=")[1].split("&")[0];
var article = href.split("?title=")[1].split("&")[0];
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?format=json&action=query&prop=revisions&rvlimit=2&rvstartid=" + oldid + "&titles=" + article, false);
req.send(null);
var info = formatResponse(eval("(" + req.responseText + ")"));
if(info.revisions) {
if(info.revisions[1]) {
var oldrev = info.revisions[1].revid;
var link = makeLink("red", wgScript + "?title=" + article + "&action=edit&oldid=" + oldrev + "&script=rv", "revert");
li.appendChild(link);
}
}
}
}