User:Animum/Sandbox: Difference between revisions

Content deleted Content added
Animum (talk | contribs)
m Replaced deprecated <source> tags with <syntaxhighlight> (via WP:JWB)
 
(27 intermediate revisions by one other user not shown)
Line 1:
<syntaxhighlight lang="JavaScript">
<!-- -->
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);
}
}
}
}
</syntaxhighlight>