User:Quarl/show diff since.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:Quarl/show diff since. |
// User:Quarl/show_diff_since.js - add 'since' tab to show change since I last edited
// Compared to JesseW's, this is an asynchronous version that doesn't first open the history page
// requires: wikipage.js
// idea based on http://en.wikipedia.org/wiki/Wikipedia:WikiProject_User_scripts/Scripts/Changes_since_I_last_edited
// from http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510
// but rewritten using AJAX
// <pre><nowiki>
function addTab_DiffSince() {
if (wikiPage.nsSpecialP) return;
addTab('javascript:show_diff_since()', 'since', 'ca-since', "Changes since I last edited");
}
function show_diff_since() {
var tab = document.getElementById('ca-since');
// show the user we're doing something
tab.innerHTML = '<b>since...</b>';
var url = wikiPage.qurl + '&action=history';
var req = new XMLHttpRequest();
// using onload instead of onreadystatechange allows multiple asynchronous requests
req.onload = show_diff_since_handleHistoryPage;
req.overrideMimeType('text/xml');
req.open("GET", url, true);
req.send(null);
}
// <li>(<a href="/w/index.php?title=ARTICLETITLE&diff=35459147&oldid=35392123" title="ARTICLETITLE">cur</a>) *
// \(<a href[^>]+?> *<input[^>]+?>
// <span class='history-user'><a href="/wiki/User:Quarl" title="User:Quarl">Quarl</a></span>
function show_diff_since_handleHistoryPage(event) {
var req = event.target;
if (req.readyState == 4) {
if ((req.status == 200)) {
// window.username is defined in wikipage.js
//var re = '<li>\\(<a href="(/w/index\\.php\\?title=[^&"]+?&diff=[0-9]+?&oldid=[0-9]+?)" title="[^"]+?">cur</a>\\)[^\n]+?<span class=\'history-user\'><a href="[^"]+?" title="[^"]+?">'+window.username+'</a></span>';
/*if (req.responseText.match(new RegExp(re))) {
var url = RegExp.$1.replace('&','&');
document.location = url;
} else {
alert("Couldn't find your entry in the history page");
// TODO: perhaps retry with a larger limit
}*/
show_diff_since_examineTree(req.responseXML);
} else {
alert("Error downloading history page");
}
}
}
function show_diff_since_examineTree(doc) {
var hists = doc.getElementById("pagehistory").childNodes;
for (n=0;n<hists.length;n++) {
if (hists[n].getElementsByTagName("span")[0].textContent==window.username) {
document.location = hists[n].childNodes[1].href;
return;
}
}
alert("Couldn't find your entry in the history page!");
// TODO: perhaps retry with a larger limit
}
addOnloadHook(addTab_DiffSince);
// </nowiki></pre>