User:Sander Säde/pagesCreated.js

/* Script to show pages in mainspace created by user. Alpha stage.

$(pagesCreatedHook); var cpUserName = ""; var cpBody = ""; var cpOffset = 2; //time offset

//from User:Lupin/nichalpCustomLinks function addToolboxLink(url, name, id){ var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0]; addlilink(tb, url, name, id); }

function pagesCreatedHook { if ((document.URL.indexOf('/User:') != -1) || (document.URL.indexOf('/User_talk:') != -1)) { if (mw.config.get('wgTitle').indexOf("/") != -1) return; //subpages addToolboxLink('javascript:pagesCreated','Created pages', 'pgCreated'); }

if (document.URL.indexOf('Special:Contributions/') != -1) addToolboxLink('javascript:pagesCreated','Created pages', 'pgCreated');

}

function pagesCreated { if (cpUserName == "") cpUserName = mw.config.get('wgTitle'); if (cpUserName == 'Contributions') { var name = document.getElementById("contentSub").getElementsByTagName("a"); cpUserName = name[0].innerHTML; //IP's       if (cpUserName == "Talk") { cpUserName = document.getElementById("contentSub").innerHTML.split(" ")[1]; } }

var cpaj = sajax_init_object(null); cpaj.open("GET", "http://en.wikipedia.org/w/query.php?what=usercontribs&titles=User:" + escape(cpUserName) + "&uclimit=500&uccomments&format=json&noprofile", true); cpaj.onreadystatechange = function {     if(cpaj.readyState == 4) cpResultsReceived(cpaj.responseText); };   cpaj.send(null); }

function anyChild(obj) { for(var key in obj) { return obj[key]; }  return null; }

function cpResultsReceived(jsonObj) { eval("var queryResult=" + jsonObj); var page = anyChild(queryResult.pages); var links = page.contributions; cnt = 0; cpBody = ""; for (i = 0; i < links.length; i++) { if (links[i].new != null) { addToBodyContent(links[i]); cnt++; } }

cpt = " Page creations in last 500 edits for " + cpUserName +  ' '; if (cnt == 0) cpt += "No"; else cpt += cnt;

cpt += ' pages created. ' + "\r\n"; cpBody = cpt + cpBody + ''; document.getElementById("bodyContent").innerHTML = cpBody ; }

function addToBodyContent(entry) { cpBody += '\r\n' + cpGetTime(entry.timestamp) + ' (hist)  ' + entry.* + ' (' + entry.comment + ') '; }

function cpGetTime(cpTime) { var arrDate = new Array; arrDate = cpTime.split("T")[0].split("-"); var arrTime = new Array; arrTime = cpTime.split("T")[1].split(":"); arrTime[2] = arrTime[2].replace("Z",""); //cpDate = new Date(Date.UTC(arrDate[0],arrDate[1],arrDate[2],arrTime[0], arrTime[1], arrTime[2])); cpDate = new Date; cpDate.setFullYear = (arrDate[0],arrDate[1],arrDate[2]); cpDate.setHours(Number(arrTime[0]) + cpOffset, arrTime[1], arrTime[2]); return cpDate.toLocaleString; }