User:Walrus068/recentchanges.js

// ';   this.rcBody = a.childNodes[1].childNodes[1]; } RecentChanges.createEntry = function createEntry(a) { var blocklink, rollbacklink, difference = a.newlen - a.oldlen, tr1 = document.createElement("tr"), tr2 = document.createElement("tr"), timestamp = document.createElement("td"), title = document.createElement("td"), diff = document.createElement("td"), userlinks = document.createElement("td"), comment = document.createElement("td"), undolinks = document.createElement("td"), titlelink = document.createElement("a"), difflink = document.createElement("a"), histlink = document.createElement("a"), editlink = document.createElement("a"), userpagelink = document.createElement("a"), usertalklink = document.createElement("a"), usercontribslink = document.createElement("a"), undolink = document.createElement("a"), urltitle = encodeURIComponent(a.title.replace(/ /g, "_")), urluser = encodeURIComponent(a.user.replace(/ /g, "_")), pos_diff = difference > 0; titlelink.href = wgScript + "?title=" + urltitle; difflink.href = wgScript + "?title=" + urltitle + "&diff=" + a.revid; histlink.href = wgScript + "?action=history&title=" + urltitle; editlink.href = wgScript + "?action=edit&title=" + urltitle; userpagelink.href = wgScript + "?title=User:" + urluser; usertalklink.href = wgScript + "?title=User_talk:" + urluser; usercontribslink.href = wgScript + "?title=Special:Contributions/" + urluser; undolink.href = wgScript + "?action=edit&undo=" + a.revid + "&undoafter=" + a.old_revid + "&title=" + urltitle; timestamp.innerHTML = a.timestamp.substring(a.timestamp.indexOf("T") + 1, a.timestamp.indexOf("Z")); titlelink.innerHTML = a.title; difflink.innerHTML = "diff"; histlink.innerHTML = "hist"; editlink.innerHTML = "edit"; diff.innerHTML = (pos_diff ? "+" : "") + difference; userpagelink.innerHTML = a.user; usertalklink.innerHTML = "talk"; usercontribslink.innerHTML = "contribs"; comment.innerHTML = a.parsedcomment; undolink.innerHTML = "undo"; titlelink.target = "_blank"; difflink.target = "_blank"; histlink.target = "_blank"; editlink.target = "_blank"; userpagelink.target = "_blank"; usertalklink.target = "_blank"; usercontribslink.target = "_blank"; undolink.target = "_blank"; diff.className = "mw-plusminus-" + (pos_diff ? "pos" : "neg"); tr2.className = a.revid; timestamp.setAttribute("rowspan", "2"); title.appendChildren(document.createTextNode("["), difflink, document.createTextNode("|"), histlink, document.createTextNode("|"), editlink, document.createTextNode("] "), titlelink); userlinks.appendChildren(userpagelink, document.createTextNode(" ["), usertalklink, document.createTextNode("|"), usercontribslink, document.createTextNode("]")); undolinks.appendChildren(document.createTextNode("["), undolink); if (this.hasRollback) { rollbacklink = document.createElement("a"); rollbacklink.href = wgScript + "?action=rollback&from=" + urluser + "&title=" + urltitle + "&token="; //token gets added later rollbacklink.innerHTML = "rollback"; rollbacklink.target = "_blank"; rollbacklink.className = "RecentChanges-rollback-link"; undolinks.appendChildren(document.createTextNode("|"), rollbacklink); }   if (this.isSysop) { blocklink = document.createElement("a"); blocklink.href = wgScript + "?title=Special:Block/" + urluser; blocklink.innerHTML = "block"; blocklink.target = "_blank"; undolinks.appendChildren(document.createTextNode("|"), blocklink); }   undolinks.appendChild(document.createTextNode("]")); tr1.appendChildren(timestamp, title, diff, userlinks); tr2.appendChildren(comment, document.createElement("td"), undolinks); this.rcBody.appendChildren(tr1, tr2); }; RecentChanges.load = function load { "use strict"; var xhr = new XMLHttpRequest; xhr.onreadystatechange = function { if (this.readyState === 4 && this.status === 200) { var i, xhr, a = JSON.parse(this.responseText).query.recentchanges, revs = []; RecentChanges.rcBody.innerHTML = null; for (i = 0; i < a.length; i = i + 1) { RecentChanges.createEntry(a[i]); revs.push(a[i].revid); }           if (RecentChanges.hasRollback) { xhr = new XMLHttpRequest; xhr.onreadystatechange = function { if (this.readyState === 4 && this.status === 200) { var i, o, a, b = JSON.parse(this.responseText).query, c = b.pageids; for (i = 0; i < c.length; i = i + 1) { a = b.pages[c[i]].revisions; for (o = 0; o < a.length; o = o + 1) { document.getElementsByClassName(a[o].revid)[0].getElementsByClassName("RecentChanges-rollback-link")[0].href += encodeURIComponent(a[o].rollbacktoken); }                       }                    }                };                xhr.open("GET", wgScriptPath + "/api.php?format=json&action=query&prop=revisions&rvtoken=rollback&indexpageids&revids=" + revs.join("|"), true); xhr.send; }       }    };    xhr.open("GET", wgScriptPath + "/api.php?format=json&action=query&list=recentchanges&rcshow=!bot&rctype=edit|new&rclimit=15&rcprop=ids|sizes|timestamp|user|title|parsedcomment", true); xhr.send; }; if (wgPageName === "User:Walrus068/RecentChanges") { addEventListener("DOMContentLoaded", function {        "use stict";        RecentChanges.init;        RecentChanges.load;        setInterval(RecentChanges.load, 5e3);    }, true); }