User:CharlotteWebb/history filter.js

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 += ' | show my edits only'); ul.innerHTML=""; document.getElementById("contentSub").innerHTML += ' | show all edits'; 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 = ' ' + (user == wgUserName ? "you have" : user + " has") + ' never edited this page, or else there is ' +     'a bug somewhere\u2026'); difflink = function(r1, r2, a) { return('' + a + ''); }   oldidlink = function(r, a) { return('' + a + ''); }   radio = function(r, n) { return(' '); }   userlinks = function(u) { return('' +       u + ' (' + "talk" + ' | ' + "contribs" + ') '); }   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]) + " " + ' ' + userlinks(user) + " " + (minor ? ' m ' : "") + (bytes ? ' (' + bytes.replace(/(\d)(\d\d\d)$/, "$1,$2") + ' bytes) ' : "") + (sum ? ' (' + sum + ') ' : "") +'</li>'; }   ul.innerHTML = s;    } ul.innerHTML = "<li>scraping from api.php, please wait\u2026</li>"; x.send(""); } $(history_filter);