User:Dinnerbone/Vandal box/script.js

//

////////////////////////////////////// //    START OF GLOBAL VARIABLES    // //////////////////////////////////////

if(typeof vbTemplates == "undefined") { vbTemplates = new Array; vbTemplates[0] = "test#Unintentional vandalism"; vbTemplates[1] = "test2#Nonsense"; vbTemplates[2] = "test2b#Blankings/Content removal"; vbTemplates[3] = "test3#Please stop"; vbTemplates[4] = "test4#Last warning"; vbTemplates[5] = "blatantvandal#Blatant vandal"; vbTemplates[6] = "test4im#Only warning"; }

if(typeof vbSpeedys == "undefined") { vbSpeedys = new Array; vbSpeedys[0] = "nonsense#Nonsense"; vbSpeedys[1] = "test#Test page"; vbSpeedys[2] = "vandalism#Vandalism page"; vbSpeedys[3] = "pagemove#Page move vandalism"; vbSpeedys[4] = "repost#Copy of previously deleted material"; vbSpeedys[5] = "banned#Made by banned user"; vbSpeedys[6] = "empty#Little/no context"; vbSpeedys[7] = "foreign#Non-English article"; vbSpeedys[8] = "afd#AFD closed as 'delete'"; vbSpeedys[9] = "g6#Housekeeping tasks (see WP:CSD#G6)"; vbSpeedys[10] = "author#Speedy request by author"; vbSpeedys[11] = "blanked#Page blanked by author"; vbSpeedys[12] = "talk#Talk page of deleted article"; vbSpeedys[13] = "attack#Attack page"; vbSpeedys[14] = "spam#Advertising page"; vbSpeedys[15] = "nocontent#Contains only external links"; vbSpeedys[16] = "transwiki#Transwikification complete"; vbSpeedys[17] = "bio#Non-notable biography"; vbSpeedys[18] = "band#Non-notable band"; vbSpeedys[19] = "club#Non-notable club"; vbSpeedys[20] = "group#Non-notable group"; vbSpeedys[21] = "web#Non-notable website"; }

////////////////////////////////////// //     END OF GLOBAL VARIABLES     // ////////////////////////////////////// //     START OF DOM FUNCTIONS      // //////////////////////////////////////

function getElementsByClass(needle) { function _GetElementsByClass(outArray, seed, needle) {   while (seed) { if (seed.nodeType == Node.ELEMENT_NODE) { if (seed.hasAttribute("class")) { var c = " " + seed.className + " "; if (c.indexOf(" " + needle + " ") != -1) outArray.push(seed); }       _GetElementsByClass(outArray, seed.firstChild, needle) }     seed = seed.nextSibling; } }

var outArray = new Array; _GetElementsByClass(outArray, document.documentElement, needle); return outArray; }

function getElementsByTitle(title, element) { var tResults = new Array; var elements = element.getElementsByTagName('*'); for (var i=0; i<elements.length; i++) { if (elements[i].getAttribute('title') && elements[i].getAttribute('title') == title) { tResults.push(elements[i]); }   }    return tResults; }

function addRow(leftT, tRight, table) { var row = document.createElement("tr"); var left = document.createElement("td"); var right = document.createElement("td"); table.appendChild(row); row.appendChild(left); row.appendChild(right);

left.appendChild(leftT); right.appendChild(tRight); }

function addPar(to) { var par = document.createElement("p"); to.appendChild(par); return par; }

function addLink(url, text) { var aa = document.createElement("a"); aa.href = url; aa.appendChild(text || addText(url)); return aa; }

function addText(text) { return document.createTextNode(text + "\n"); }

function addTable(to) { var table = document.createElement("table");

to.appendChild(table); return table; }

function addStrong(text) { var tNode = document.createTextNode(text); var strong = document.createElement("strong"); strong.appendChild(tNode); return strong; }

////////////////////////////////////// //      END OF DOM FUNCTIONS       // ////////////////////////////////////// //    START OF VBOX FUNCTIONS      // //////////////////////////////////////

function addTab(url, name, id, title, key){ var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; return addlilink(tabs, url, name, id, title, key) }

function addlilink(tabs, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) {       if(key && title) {           ta[id] = [key, title]; }       else if(key) {           ta[id] = [key, '']; }       else if(title) {           ta[id] = ['', title]; }   }    // re-render the title and accesskeys from existing code in wikibits.js    akeytt; return li; }

function getParams { var idx = document.URL.indexOf('?'); var params = new Array; if (idx != -1) { var pairs = document.URL.substring(idx+1, document.URL.length).split('&'); for (var i=0; i 0) messages.value += '\r';

summary.value = " using vBox"; messages.value += "" + page + " ~";

document.editform.wpSave.click; cBox.innerHTML = ' &lt; User:Dinnerbone | Vandal box \n'; //If we are going to blank the page, it may as well have a link to VB on it...

var par = addPar(cBox); par.appendChild(addText("Please wait while the page loads...")); }

function revertPage { var form = document.editform; if(!isIP(decodeTitle(params["vname"]))) { form.wpSummary.value = "Reverting to " + params["oldid"] + " by " + decodeTitle(params["vname"]) + " using vBox"; }   else { form.wpSummary.value = "Reverting to " + params["oldid"] + " by " + decodeTitle(params["vname"]) + " using vBox"; }   form.wpSave.click; cBox.innerHTML = ' &lt; User:Dinnerbone | Vandal box \n'; //If we are going to blank the page, it may aswel have a link to VB on it...

var par = addPar(cBox); par.appendChild(addText("Please wait while the page loads...")); }

function markSpeedy { var form = document.editform; var tSplit = vbSpeedys[params["Template"]].split("#", 2); var template = tSplit[0]; form.wpSummary.value = " using vBox"; form.wpTextbox1.value = "\n\n" + form.wpTextbox1.value; form.wpSave.click; cBox.innerHTML = ' &lt; User:Dinnerbone | Vandal box \n';

var par = addPar(cBox); par.appendChild(addText("Please wait while the page loads...")); }

function reportAIV { var form = document.editform; var user = params["vbuser"]; var reason = unescape(params["vbreason"]);

if(isIP(user)) { form.wpTextbox1.value += "* - " + reason + " --~"; form.wpSummary.value = "Reporting " + user + " using vBox"; }

else { form.wpTextbox1.value += "* - " + reason + " --~"; form.wpSummary.value = "Reporting " + user + " using vBox"; }   form.wpSave.click; cBox.innerHTML = ' &lt; User:Dinnerbone | Vandal box</a> \n';

var par = addPar(cBox); par.appendChild(addText("Please wait while the page loads...")); }

function reportAIVprompt { var reason = prompt("Why are you reporting this user?\nNote: this is not required, but it is highly recommended that you fill this in."); if(reason == "null") return; document.location = "/w/index.php?title=Wikipedia:Administrator_intervention_against_vandalism&action=edit&vbox=report&vbuser=" + wgPageName.split(":", 2)[1].split("/")[0] + "&vbreason=" + escape(reason); }

function isIP(testee) { if(testee.match(/[a-z]/i)) { return false; }   return true; }

////////////////////////////////////// //     END OF VBOX FUNCTIONS       // ////////////////////////////////////// //     START OF MAIN FUNCTIONS     // //////////////////////////////////////

function showVBox { cBox.innerHTML = ' &lt; <a href="/wiki/User:Dinnerbone">User:Dinnerbone</a> | <a href="/wiki/User:Dinnerbone/Vandal_box">Vandal box</a> \n';

if(params["vbox"] == "" || params["vbox"] == undefined) { var par1 = addPar(cBox); var par2 = addPar(cBox); par1.appendChild(addText('Please go to ')); par1.appendChild(addLink('/wiki/User:Dinnerbone/Vandal_box', addText('User:Dinnerbone/Vandal_box'))); par1.appendChild(addText(' if you are looking for Vandal Box.')); par2.appendChild(addText('If you have installed Vandal Box, but keep getting this page when you use the "vandal box" tab, please see ')); par2.appendChild(addLink('/wiki/User:Dinnerbone/Vandal box#Troubleshooting', addText('User:Dinnerbone/Vandal box#Troubleshooting'))); par2.appendChild(addText(' or leave a message on ')); par2.appendChild(addLink('/wiki/User talk:Dinnerbone/Vandal box', addText('User talk:Dinnerbone/Vandal box'))); return; }   if(params["vbox"] == "warn") { var table = addTable(cBox);

for(var i=0; i<=vbTemplates.length; i++) { var tSplit = vbTemplates[i].split("#", 2); var link = '/w/index.php?title=User_talk:' + params['Name'] + '&action=edit&Template=' + i + '&vbpage=' + params["vbpage"] + '&vbox=warn'; addRow(addLink(link, addText( + decodeTitle(params["vbpage"]) + )), addText(tSplit[1]), table); }   }    if(params["vbox"] == "speedy") { var table = addTable(cBox); for(var i=0; i<=vbSpeedys.length; i++) { var tSplit = vbSpeedys[i].split("#", 2); var link = '/w/index.php?title=' + params['vbpage'] + '&action=edit&Template=' + i + '&vbox=speedy'; addRow(addLink(link, addText('')), addText(tSplit[1]), table); }   } }

function doHistory { var history = document.getElementById("pagehistory"); var legend = document.getElementById("histlegend"); var hItems = history.getElementsByTagName("li"); legend.innerHTML = legend.innerHTML.substr(0, legend.innerHTML.length - 1) + ", "; //Remove the full stop from the legend, replace it with a comma and a space. legend.appendChild(addStrong("(r)")); legend.appendChild(addText(" = ")); legend.appendChild(addLink("/wiki/Wikipedia:Revert#When_to_revert", addText("revert"))); legend.appendChild(addText(", ")); legend.appendChild(addStrong("(w)")); legend.appendChild(addText(" = warn user.")); for (var i=0; i<hItems.length; i++) { var item = hItems[i]; var cNodes = item.getElementsByTagName("*"); var iAfter = cNodes[5]; var fChild = iAfter.firstChild; var oldid = cNodes[2]; var user = iAfter.firstChild.textContent; var revert = addLink("/w/index.php?title=" + params["title"] + "&action=edit&oldid=" + oldid.value + "&vbox=revert&vname=" + user, addStrong("(r) ")); var warn = addLink("/wiki/User:Dinnerbone/Vandal_box/vbox?vbpage=" + params["title"] + "&Name=" + user + "&vbox=warn", addStrong("(w) ")); if(i < hItems.length-1 && i > 0) { item.insertBefore(addText(" "), cNodes[3]); item.insertBefore(warn, cNodes[5]); item.insertBefore(addText(" "), cNodes[2]); item.insertBefore(revert, cNodes[5]); }       else { item.insertBefore(warn, cNodes[4]); if(i > 0) item.insertBefore(revert, cNodes[4]); }   } }

function doRevision { var oldr = document.getElementById("differences-prevlink"); var newr = document.getElementById("differences-nextlink"); var oldid = 0; var newid = 0; if(oldr != undefined) { oldid = oldr.href.substr(params["oldid"].length * -1); var oldRow = oldr.parentNode; var oldUserr = oldRow.getElementsByTagName("*")[5]; var oldUser = oldUserr.textContent; var oldRevert = addLink("/w/index.php?title=" + params["title"] + "&action=edit&oldid=" + oldid + "&vbox=revert&vname=" + oldUser, addStrong("(Revert) ")); var oldWarn = addLink("/wiki/User:Dinnerbone/Vandal_box/vbox?vbpage=" + params["title"] + "&Name=" + oldUser + "&vbox=warn", addStrong("(Warn)")); oldRow.appendChild(document.createElement("br")); oldRow.appendChild(oldRevert); oldRow.appendChild(oldWarn); }   if(newr != undefined) { newid = newr.href.substr(params["oldid"].length * -1); var newRow = newr.parentNode; var newUserr = newRow.getElementsByTagName("*")[5]; var newUser = newUserr.textContent; var newRevert = addLink("/w/index.php?title=" + params["title"] + "&action=edit&oldid=" + newid + "&vbox=revert&vname=" + newUser, addStrong("(Revert) ")); var newWarn = addLink("/wiki/User:Dinnerbone/Vandal_box/vbox?vbpage=" + params["title"] + "&Name=" + newUser + "&vbox=warn", addStrong("(Warn)")); newRow.appendChild(document.createElement("br")); newRow.appendChild(newRevert); newRow.appendChild(newWarn); } }

function onLoadVB { params = getParams; cBox = document.getElementById("bodyContent"); if (document.title == "User:Dinnerbone/Vandal box/vbox - Wikipedia, the free encyclopedia") { showVBox; return; }   if (params["diff"] != undefined) { doRevision; }   if (params["vbox"] == "revert") { revertPage; return; }   if (params["vbox"] == "warn") { warnUser; return; }   if (params["vbox"] == "speedy") { markSpeedy; return; }   if (params["vbox"] == "report") { reportAIV; return; }   if (document.title.match(" - History - ")) { doHistory; return; }   if (document.title.match("User:") || document.title.match("User talk:")) { addTab("javascript:reportAIVprompt", "report user", "ca-reportvandal", "Report a vandal to WP:AIV", ""); return; }   if (typeof params["action"] == "undefined" && !wgPageName.match("Special:")) { addTab("/wiki/User:Dinnerbone/Vandal_box/vbox?vbpage=" + wgPageName + "&vbox=speedy", "speedy delete", "ca-speedydelete", "Tag for speedy deletion", ""); return; } }

if (window.addEventListener) window.addEventListener("load", doLoad, false); else if (window.attachEvent) window.attachEvent("onload", doLoad);

function doLoad { setTimeout(onLoadVB, 100); }

////////////////////////////////////// //      END OF MAIN FUNCTIONS      // //////////////////////////////////////

//