User:Draicone/Editcounter.js

var tool2_url = "User:Draicone/Editcounter.js"; var namespaces = [ "Media", "Special", "Talk", "User", "User talk", "Wikiversity", "Wikiversity talk", "Image", "Image talk", "MediaWiki", "MediaWiki talk", "Template", "Template talk", "Help", "Help talk", "Category", "Category talk", "School", "School talk", "Portal", "Portal talk", "Topic", "Topic talk" ]; var prefix = ""; var params = parse_params; addOnloadFunction(function { var path_len = document.location.pathname.length;  if (document.location.pathname.substring(path_len - tool2_url.length, path_len) == tool2_url) {    prefix = document.location.protocol + "//" + document.location.host + "/"            + document.location.pathname.substring(1, path_len - tool2_url.length);    var bodyContent = document.getElementById("bodyContent");    while (bodyContent.childNodes.length > 0) bodyContent.removeChild(bodyContent.lastChild);

if (document.location.search.length == 0) { generate_input_form(bodyContent); } else { generate_main_report(bodyContent); } } }); function generate_input_form(bodyContent) {  bodyContent.innerHTML =            "  ";  var form = bodyContent.getElementsByTagName("form")[0];  form.method = "get";  form.action = document.location; } function generate_main_report {  fetch_data(params["username"], "", output_main_report, 0, []); } function output_main_report(data) { } var offset_regexp = /href="[^"]+:Contributions[^"]+offset=(\d+)/gi; function fetch_data(username, end_date, handler, offset, page_list) {    var url = prefix + "Special:Contributions/" + username + "?offset=" + offset + "&limit=500";    loadXMLDoc(url,         function (request) {            var next_offset = 0;            if (request.readyState != 4)   return;            if (request.status == 200) {                page_list.push(request.responseText);                var matches = map( function(p){                        return p.match( /(\d+)$/ )[0]; }, request.responseText.match( offset_regexp ) );               for (var i=0; i<matches.length; i++) {                    var v = matches[i] * 1;                    if (v != 0 && (offset == 0 || v < offset)) {                        next_offset = v;                        break;                    }                }            }            if (next_offset == 0) {                parse_data(page_list, handler);            } else {                // tail recurse                fetch_data(username, end_date, handler, next_offset, page_list);            }        }); } function parse_data(page_list, handler) { } function dump_text(text) { var pre = document.createElement("pre"); var div = document.createElement("div"); div.style.width = "60em"; div.style.maxHeight = "40em"; div.style.overflow = "auto"; pre.appendChild(document.createTextNode(text)); div.appendChild(pre); document.getElementById("bodyContent").appendChild(div); } function dump_lines(ary) { dump_text(ary.join("\n")); } function addOnloadFunction(f) { if (window.addEventListener) window.addEventListener("load",f,false); else if (window.attachEvent) window.attachEvent("onload",f); else { var oldOnload='_old_onload_'+addOnloadFunction.uid; addOnloadFunction[oldOnload] = window.onload ? window.onload : function {}; window.onload = function { addOnloadFunction[oldOnload]; f; } ++addOnloadFunction.uid; } } function parse_params { var pairs = document.location.search.substring(1).split("&"); var ret = []; for (var i=0; i < pairs.length; i++) { var values = pairs[i].split("="); ret[values[0]] = unescape(values[1]); } return ret; } function loadXMLDoc(url, handler) {   if (window.XMLHttpRequest) { req = new XMLHttpRequest; req.onreadystatechange = function {handler(req)}; req.open("GET", url, true); req.send(null); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = function {handler(req)}; req.open("GET", url, true); req.send; }   } } function map (handler, list) { var ret = new Array; for (var i=0; i<list.length; i++) { ret[i] = handler( list[i] ); } return ret; }