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, addlilink.js
// 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
// quarl 2006-01-16 rewritten to asynchronously download history page
// TODO: use a non-async version for href, and async for onClick
// <pre><nowiki>
function addTab_DiffSince() {
if (wikiPage.nsSpecialP) return;
var url;
if (historyP) {
// already looking at history page
url = 'javascript:show_diff_since_thisHistoryPage()';
} else {
// not yet a history page -- asynchronously download it first
url = 'javascript:show_diff_since_thisPage()';
}
addTab(url, 'since', 'ca-since', "Show changes since I last edited");
}
function show_diff_since_thisPage() {
show_diff_since(wikiPage, document.getElementById('ca-since'), ' <b>since...</b> ');
}
function show_diff_since(wp, statusnode, statustext) {
var url = wp.qurl + '&action=history';
var req = new XMLHttpRequest();
if (statusnode) {
// change the button to show the user we're doing something and prevent another click
req.statusnode = statusnode;
req.save_text = statusnode.innerHTML;
statusnode.innerHTML = statustext;
}
req.onload = show_diff_since_handleHistoryPage;
req.overrideMimeType('text/xml');
req.open("GET", url, true);
req.send(null);
}
function show_diff_since_handleHistoryPage(event) {
var req = event.target;
if (req.readyState == 4) {
// restore button in case this fails, so user can click again
if (req.statusnode) {
req.statusnode.innerHTML = req.save_text;
}
if (req.status == 200) {
show_diff_since_examineTree(req.responseXML);
} else {
alert("Error downloading history page!");
}
}
}
function show_diff_since_thisHistoryPage() {
show_diff_since_examineTree(document);
}
function show_diff_since_examineTree(doc) {
if (!doc) { alert ("## no doc?!"); return; }
var hists = doc.getElementById("pagehistory").childNodes;
if (!hists) { alert("Couldn't parse history from page"); return; }
for (n=0;n<hists.length;n++) {
// window.username is defined in wikipage.js
if (hists[n].getElementsByTagName && 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>