User:CharlotteWebb/history filter.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. |
![]() | This user script seems to have a documentation page at User:CharlotteWebb/history filter. |
qs = function(){
qdo = {}, s = location.href.split("?")[1];
if(s){
p = s.split("&");
for(var i = 0; i < p.length; i++){
lv = p[i].split("=");
qdo[decodeURIComponent(lv[0])] = (lv[1] ? decodeURIComponent(lv[1]) : "");
}
}
return(qdo);
}();
months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
function history_filter(){
if(wgAction != "history") return;
ul = document.getElementById("pagehistory");
if(!ul) return;
if(qs["myeditsonly"]) user = wgUserName;
else if(qs["user"]) user = qs["user"];
else user = null;
if(!user)
return(document.getElementById("contentSub").innerHTML += ' | <a href="' +
location.href + "&myeditsonly=1" + '">show my edits only</a>');
ul.innerHTML="";
document.getElementById("contentSub").innerHTML += ' | <a href="' +
document.getElementById("ca-history").getElementsByTagName("a")[0].href +
'">show all edits</a>';
x = new XMLHttpRequest();
u = wgServer + "/w/api.php?action=query&prop=revisions&rvlimit=500&titles=" +
encodeURIComponent(mw.config.get('wgPageName')) + "&rvprop=ids|flags|timestamp|size|comment&rvuser=" +
encodeURIComponent(user) + "&format=xml";
x.open("GET", u, true);
x.onreadystatechange = function() {
if(x.readyState != 4) return;
s = "", ul = document.getElementById("pagehistory");
rev = new DOMParser().parseFromString(x.responseText, "text/xml").getElementsByTagName("rev");
if(!rev.length) return(ul.innerHTML = '<li class="error">' + (user == wgUserName ?
"you have" : user + " has") + ' never edited this page, or else there is ' +
'a bug somewhere\u2026</li>');
difflink = function(r1, r2, a) {
return('<a href="' + wgServer + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) +
'&diff=' + r1 + '&oldid=' + r2 + '" title="' + wgPageName + '">' + a + '</a>');
}
oldidlink = function(r, a) {
return('<a href="' + wgServer + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) +
'&oldid=' + r + '" title="' + wgPageName + '">' + a + '</a>');
}
radio = function(r, n) {
return(' <input type="radio" value="' + r + '" name="' + n + '" />');
}
userlinks = function(u) {
return('<a href="' + wgServer + wgArticlePath.replace("$1", "User:" + u) + '">' +
u + '</a> (<a href="' + wgServer + wgArticlePath.replace("$1", "User talk:" +
u) + '">' + "talk" + '</a> | <a href="' + wgServer +
wgArticlePath.replace("$1", "Special:Contributions/" + u) + '">' +
"contribs" + '</a>) ');
}
for(i = 0; i < rev.length; i++){
oldid = rev[i].getAttribute("revid"), bytes = rev[i].getAttribute("size");
minor = rev[i].getAttribute("minor"), sum = rev[i].getAttribute("comment");
ts = rev[i].getAttribute("timestamp").match(/(\d{4})\-(\d\d)\-(\d\d)T([\d\:]+)\:\d\dZ/);
s += '<li>(' + (oldid == wgCurRevisionId ? "cur" :
difflink(wgCurRevisionId, oldid, "cur")) + ") (" +
difflink("prev", oldid, "last") + ")" + radio(oldid, "oldid") +
radio(oldid, "diff") + " " + oldidlink(oldid, ts[4] + ", " +
parseInt(ts[3].replace("0", "")) + " " + months[parseInt(ts[2].replace("0",
""))-1] +" " + ts[1]) + " " + '<span class="history-user">' +
userlinks(user) + "</span>" +
(minor ? ' <span class="minor">m</span>' : "") +
(bytes ? ' <span class="history-size">(' + bytes.replace(/(\d)(\d\d\d)$/, "$1,$2") + ' bytes)</span>' : "") +
(sum ? ' <span class="comment">(' + sum + ')</span>' : "") +'</li>';
}
ul.innerHTML = s;
}
ul.innerHTML = "<li>scraping from api.php, please wait\u2026</li>";
x.send("");
}
$(history_filter);