User:Nx/Scripts/Vandallog.js

if (typeof nx_vandallog_servertz == "undefined") nx_vandallog_servertz = "EDT"

monthnames = {"January":0, "February":1, "March":2, "April":3, "May":4, "June":5, "July":6, "August":7, "September":8, "October":9, "November":10, "December":11, }

function parsetimestamp(timestamp) { if (timestamp == "") return null; timestamp = timestamp.replace(/(.. :)/,"20$1") + " " + nx_vandallog_servertz; var d = new Date(Date.parse(timestamp)); return {"hours":d.getHours,"minutes":d.getMinutes,"day":d.getDate,"month":d.getMonth,"year":d.getFullYear}; }

function exts(raw) { return raw.substring(raw.lastIndexOf("at")+3); }

function vandalentry(h,m,raw) { /* var mc = raw.match(/^(.*) has been (.*) by (.*) at .*$/); var user1 = mc[1]; var user2 = mc[3]; var act = mc[2];*/

return '(Vandal bin log); ' + (h < 10 ? "0"+h : h) + ":" + (m < 10 ? "0"+m : m) + " . . " + raw.substring(0,raw.lastIndexOf("at")-1); //user1 + " has been " + act + " by " + user2; }

function vandalinsert(raw) { var events = raw.split(//); events.pop; if (events[events.length-1] == "") events.pop; var lists = getElementsByClassName(document.getElementById("content"),"ul","special"); var evi = events.length-1; for (var i=lists.length-1;i>=0;--i) {   var list = lists[i].getElementsByTagName("li") var m = lists[i].previousSibling.previousSibling.innerHTML.match(/^(..) (.*) (....)$/); var lm = monthnames[m[2]]; var ld = m[1]; var ly = m[3]; for (var j=list.length;j>0;--j) {          var lh = (list[j-1].innerHTML.match(/; ([0-9][0-9]):([0-9][0-9]). . /))[1];     var lmin = (list[j-1].innerHTML.match(/; ([0-9][0-9]):([0-9][0-9]). . /))[2];     var cont = true; while (cont) { if (evi >= 0) { var d = parsetimestamp(exts(events[evi])); if (d == null) { --evi; } else if (d["year"] < ly) { --evi; } else if (d["year"] == ly && (d["month"] < lm || (d["month"] == lm && d["day"] < ld))) { --evi; }         else if (d["year"] == ly && d["month"] == lm && d["day"] == ld) {           if (d["hours"] < lh || (d["hours"] == lh && d["minutes"] <= lmin)) {             var newli = document.createElement("li"); newli.innerHTML = vandalentry(d["hours"],d["minutes"],events[evi]); if (j == list.length) { lists[i].appendChild(newli); } else { lists[i].insertBefore(newli,list[j]) } --evi; } else { cont = false; } } else { cont = false; } } else { cont = false; } }   }    var cont = true; while (cont) {     if (evi >= 0) { var d = parsetimestamp(exts(events[evi])); if (d["year"] == ly && d["month"] == lm && d["day"] == ld) {         var newli = document.createElement("li"); newli.innerHTML = vandalentry(d["hours"],d["minutes"],events[evi]); if (list.length == 0) { lists[i].appendChild(newli); } else { lists[i].insertBefore(newli,list[0]) }         --evi; } else { cont = false; }     } else { cont = false; } } } }

function vandallog { if (wgPageName != "Special:Recentchanges") return; var req = sajax_init_object; if (!req) return; req.open("POST",wgServer + "/vandal.php",true); req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); req.onreadystatechange = function {   if (req.readyState == 4 && req.status == 200) {     vandalinsert(req.responseText); } }  req.send("more=1"); }

//addOnloadHook(vandallog);