User:MisterPepe/AVT/test.js

// //Preincludes for AVT

function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) { var node = document.getElementById(portlet); if ( !node ) return null; node = node.getElementsByTagName( "ul" )[0]; if ( !node ) return null;

var link = document.createElement( "a" ); link.appendChild( document.createTextNode( text ) ); link.href = href;

var item = document.createElement( "li" ); item.appendChild( link ); if ( id ) item.id = id;

if ( accesskey ) { link.setAttribute( "accesskey", accesskey ); tooltip += " ["+accesskey+"]"; }	if ( tooltip ) { link.setAttribute( "title", tooltip ); }	if ( accesskey && tooltip ) { updateTooltipAccessKeys( new Array( link ) ); }

if ( nextnode && nextnode.parentNode == node ) node.insertBefore( item, nextnode ); else node.appendChild( item ); // IE compatibility (?)

return item; } //

// function addlimenu(tabs, name, id) {   (na = document.createElement("a")).appendChild(document.createTextNode(name)); na.href = "#"; var mn = document.createElement("ul"); (li = document.createElement("li")).appendChild(na); li.appendChild(mn); if(id) li.id = id; li.className = 'tabmenu'; tabs.appendChild(li); return mn; // useful because it gives us the  to add s to } //

// //Start main script update function addExtraLinks //Adds Logs, Noticeboard, Contribs, Userspace, and Diff links. Last three will not appear in compatibility mode. {  addPortletLink("p-tb", "http://wiki.guildwars.com/index.php?title=Guild_Wars_Wiki:Admin_noticeboard", "GWW:NOTICE", "tb-notice", "Administrator noticeboard"); addPortletLink("p-tb", "http://wiki.guildwars.com/wiki/Special:Log", "Logs", "tb-logs", "View the log files");

if (!AVTCompatibilityMode) {     if (wgCanonicalNamespace != "Special") addPortletLink('p-cactions', 'http://wiki.guildwars.com/index.php?title=' + wgPageName + "&diff=cur&oldid=prev", 'last', 'ca-last', 'Show most recent diff'); if (wgTitle.indexOf("/") != -1 || document.title.indexOf("- History -") != -1) //no subpages or history return; if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") {          var username = encodeURIComponent( wgTitle ); addPortletLink("p-cactions", "http://wiki.guildwars.com/wiki/Special:Contributions/" + username, "Contribs", "ca-contrib", "User contributions"); addPortletLink("p-cactions", "http://wiki.guildwars.com/index.php?title=Special%3APrefixindex&from=" + username + "&namespace=2", "Userspace", "", "List of pages in this user's userspace"); }   } } addOnloadHook(addExtraLinks);

//Preincludes for AVT restore function function getElementsByClass(searchClass,node,tag) { // Function from http://www.dustindiaz.com/getelementsbyclass/ var classElements = new Array; if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } }  return classElements; }

// _GET code from NoGray JS Library http://www.nogray.com/new_site/ // Used in the AVT restore function var _GET = new Array; var _uri = location.href;

var _temp_get_arr = _uri.substring(_uri.indexOf('?')+1, _uri.length).split("&");

var _temp_get_arr_1 = new Array;

for(_get_arr_i=0; _get_arr_i<_temp_get_arr.length; _get_arr_i++){ _temp_get_arr_1 = _temp_get_arr[_get_arr_i].split("="); _GET[decodeURI(_temp_get_arr_1[0])] = decodeURI(_temp_get_arr_1[1]); } //End AVT restore function preincludes

function AVTDelTag {   if (document.URL.lastIndexOf("&speedy=off") != -1) //checks for normal deletion and prompts for reason {     var type = prompt("Enter reason for deletion"); if (type == null) return; var f = document.editform, t = f.wpTextbox1; t.value = "\n" + t.value; f.wpSummary.value = "+deletion tag - AVT"; //Shameless self-promotions ftw f.wpSave.click; return; }   var reason = '';  //This next part got a lot easier when I stopped caring and just slammed out some code at 2am while under the influence quite a lot of Mountain Dew and listening to very loud music if (location.search) {     var l = location.search.substring(1).split('&'); for (var i = 0; i < l.length; ++i) {         var eq = l[i].indexOf('='); var name = l[i].substring(0, eq); if (name == 'speedy') reason = l[i].substring(eq + 1); }     var f = document.editform, t = f.wpTextbox1; t.value = "\n" + t.value; f.wpSummary.value = "Speedy deletion request per " + reason + " - AVT"; f.wpSave.click; }   return; }

function AVTWarning {  if (document.URL.lastIndexOf("&type=ohelothar") != -1) {     var f = document.editform, t=f.wpTextbox1; t.value = t.value + "\n" + wgTitle + " ~\n"; f.wpSummary.value = "Welcome to GWW! - AVT."; f.wpSave.click; return; }  var message = ''; if (location.search) {     var l = location.search.substring(1).split('&'); for (var i = 0; i < l.length; ++i) {         var eq = l[i].indexOf('='); var name = l[i].substring(0, eq); if (name == 'type') message = l[i].substring(eq + 1); }     var f = document.editform, t = f.wpTextbox1; t.value = t.value + "\n\n"; f.wpSummary.value = "User warning - AVT"; f.wpSave.click; }  return; }

function AVTReport {  var message = "~"; var type = ''; var target = ''; if (location.search) {      var l = location.search.substring(1).split('&'); for (var i = 0; i < l.length; ++i) {         var eq = l[i].indexOf('='); var name = l[i].substring(0, eq); if (name == 'reason') type = l[i].substring(eq + 1); else if (name == 'faketarget') target = unescape(l[i].substring(eq + 1)).replace(/_/g, ' '); }      switch (type) {         case 'ampersand': message = "Another one of those AmpersandBots getting rid of + signs. ~"; break; case 'warned': message = "Ignored talk page warning, still vandalizing. ~"; break; case 'vandal': message = "Vandal. ~"; break; case 'tor': message = "IP vandal using a Tor exit node. ~"; break; case 'proxy': message = "IP vandal going through an open proxy. ~"; break; case 'blank': message = "Page blanking. ~"; break; case 'custom': message = prompt("Enter custom report message"); if (message == null) {               message = "~"; }            else {               message = message + " ~"; }            break; }  }   var f = document.editform, t=f.wpTextbox1; t.value = t.value + "\n===Special:Contributions/" + target + "===\n" + message; f.wpSummary.value = "Adding vandal report - Special:Contributions/" + target + " - AVT."; f.wpSave.click;

return; }

function AVTBlock //Note that this just auto-fills the form - there's no way in hell I'm making a one-click block function. Dirigible would kill me... {  var l, target = ''; // Look for '&faketarget=XXX' in URL url = location.pathname; l = location.search.substring(1).split('&'); for (i = 0; i < l.length; i++) { var n = l[i].indexOf('='); if (l[i].substring(0, n) == 'faketarget') {        target = unescape(l[i].substring(n + 1)).replace(/_/g, ' '); }  }   if (!target) return; form = document.getElementById('blockip'); if (!form) return; input = form.getElementsByTagName('input')[0]; input.value = target; }

function AVTDelete //Sysop-only deletion function {   if (document.URL.lastIndexOf("&reason=ask") != -1) //checks for normal deletion and prompts for reason. It's a little existential, no?   { var type = prompt("Enter reason for deletion"); if (type == null) return; document.getElementById('wpReason').value = type; document.getElementById('deleteconfirm').submit; return; }   var type = ''; var summary = ''; if (location.search) {      var l = location.search.substring(1).split('&'); for (var i = 0; i < l.length; ++i) {         var eq = l[i].indexOf('='); var name = l[i].substring(0, eq); if (name == 'reason') type = l[i].substring(eq + 1); }      switch (reason) {         case 'pending': message = "Deletion uncontested after three days"; break; case 'vandal': message = "Speedy G1: Purely vandalism"; break; case 'move': message = "Page moved to more appropriate title"; break; case 'unimage': message = "Unused image"; break; case 'user': message = "Deletion per user request"; break; case 'guild': message = "Guild page has not been cleaned up within the half-fortnight limit"; break; case 'userimage': message = "Improper user image naming"; break; case 'guildimage': message = "Improper guild image naming"; break; case 'rplimage': message = "Image has been replaced"; break; default: return; break; }      document.getElementById('wpReason').value = summary + " - AVT"; document.getElementById('deleteconfirm').submit; }   return; }

//creates the extra tab - overloaded, will only show options applicable to the namespace. AVTDelTabs turns off the deletion tab for compatibility. function AVTtabs {  //stores page location in a variable for use in links var title = wgPageName.replace("&", "%26").replace("+", "%21");

//User talk namespace - vandal warning functions (and welcome template ^_^ ) if (wgNamespaceNumber ==3) {     var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; addlimenu(tabs, "Warn", "warn" ); addPortletLink("warn", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=warn&type=vandal&title=" + title, "vandal", "vand", "Warn vandal", ""); addPortletLink("warn", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=warn&type=WarnTest&title=" + title, "Test 1", "test1", "Basic test warning", ""); addPortletLink("warn", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=warn&type=test2&title=" + title, "Test 2", "test2", "Strong test warning", ""); addPortletLink("warn", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=warn&type=spam&title=" + title, "Spam", "spam", "Warn spammer", ""); addPortletLink("warn", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=warn&type=ohelothar&title=" + title, "Welcome", "hello", "Add a welcome message", ""); }

//Sysop tab with one-click deletion and simplified blocking if AVTSysop is true if (AVTSysop && wgCanonicalNamespace != "Special") {     var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; addlimenu(tabs, "Sysop", "sys" ); if (location.href.indexOf('Special:Contributions') == -1) {        addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=" + title + "&action=delete&fakeaction=delete&reason=vandal", "Vandalism", "del-ui", "Delete purely vandalism page", ""); addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=" + title + "&action=delete&fakeaction=delete&reason=pending", "Uncontested", "del-ui", "Deletion tag uncontested after three days", ""); addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=" + title + "&action=delete&fakeaction=delete&reason=ask", "Custom reason", "del-ui", "Delete with custom reason", ""); if (wgNamespaceNumber ==6) {           addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=" + title + "&action=delete&fakeaction=delete&reason=unimage", "Unused Image", "del-ui", "Delete unused image", ""); addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=" + title + "&action=delete&fakeaction=delete&reason=rplimage", "Replaced", "del-rpl", "Delete replaced image", ""); addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=" + title + "&action=delete&fakeaction=delete&reason=guildimage", "Naming (Guild)", "del-un", "Incorrect guild image naming", ""); addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=" + title + "&action=delete&fakeaction=delete&reason=userimage", "Naming (User)", "del-us", "Incorrect user image naming", ""); addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=" + title + "&action=delete&fakeaction=delete&reason=user", "User request", "del-ur", "Delete per user request", ""); }        else if (wgNamespaceNumber ==100) addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=" + title + "&action=delete&fakeaction=delete&reason=guild", "Guild cleanup", "del-ui", "Guild cleanup template not removed within a week", ""); else if (wgNamespaceNumber ==2) addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=" + title + "&action=delete&fakeaction=delete&reason=user", "User request", "del-ur", "Delete per user request", ""); }  }

//Checks to see if delete tab is enabled if (AVTDeltabs){ //Creates "Delete" tab overloaded by namespace. Game link and talk namespaces not supported in delete function. if (wgNamespaceNumber ==0 || wgNamespaceNumber ==2 || wgNamespaceNumber ==4 || wgNamespaceNumber ==6 || wgNamespaceNumber ==10 || wgNamespaceNumber ==12 || wgNamespaceNumber ==14 || wgNamespaceNumber ==100 ) {     var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; addlimenu(tabs, "Delete", "del" ); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=off&title=" + title, "delete", "del-0", "Nominate article for deletion", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=G1&title=" + title, "G1: Vandalism", "del-G1", "G1: Purely vandalism/spam", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=G2&title=" + title, "G2: Test Page", "del-G2", "G2: Page created for testing purposes", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=G3&title=" + title, "G3: Author Request", "del-G3", "G3: Sole author's request (within 24 hours)", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=G4&title=" + title, "G4: Housekeeping", "del-G4", "G4: Non-controversial housekeeping", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=G5&title=" + title, "G5: Attack Page", "del-G5", "G5: Attack page", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=G6&title=" + title, "G6: Recreated", "del-G6", "G6: Recreation of previously deleted page", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=G7&title=" + title, "G7: Arbcomm", "del-G7", "G7: Deletion per ArbComm ruling", "");

//Main (encyclopedia) namespace if (wgNamespaceNumber ==0) { addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=A1&title=" + title, "A1: Empty", "del-A1", "A1: No information on the topic", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=A2&title=" + title, "A2: Speculation", "del-A2", "A2: Unsourced speculation or wild-assed guesswork", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=R1&title=" + title, "R1: Cross-namespace", "del-R1", "R1: Redirect from Main to Guild/User namespace", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=R2&title=" + title, "R2: Implausible", "del-R2", "R2: Implausible redirect", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=R3&title=" + title, "R3: Misleading", "del-R3", "R3: Blatantly misleading redirect", ""); }

//User namespace else if (wgNamespaceNumber ==2) { addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=U1&title=" + title, "U1: User request", "del-U1", "U1: User has requested deletion", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=U2&title=" + title, "U2: Non-existant", "del-U2", "U2: User does not exist", ""); }

//Image namespace else if (wgNamespaceNumber ==6) { addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=I1&title=" + title, "I1: Redundant", "del-I1", "I1: Redundant image", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=I2&title=" + title, "I2: Corrupt", "del-I2", "I2: Corrupt/unviewable image", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=I3&title=" + title, "I3: CopyVio", "del-I3", "I3: Blatant copyright violation", ""); addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=I4&title=" + title, "I4: GWW:USER", "del-I4", "I4: Violation of GWW:USER", ""); }     //Category namespace else if (wgNamespaceNumber ==14) { addPortletLink("del", "http://wiki.guildwars.com/index.php?&action=edit&fakeaction=deltag&speedy=C1&title=" + title, "C1: Empty", "del-C1", "C1: Empty/Unused category", ""); }  }   }

//Noticeboard and IP lookup functions if (location.href.indexOf('Special:Contributions') != -1 || wgNamespaceNumber ==2 || wgNamespaceNumber ==3) {     var addr; if (wgCanonicalNamespace == "Special" && wgCanonicalSpecialPageName == "Contributions") addr = document.forms[0].target.value; else if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") addr = wgTitle; else return;

if (wgTitle.indexOf("/") != -1 || document.title.indexOf("- History -") != -1) //no subpages or history return;

//GWW:NOTICE creation links var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; addlimenu(tabs, "report", "note" ); addPortletLink("note", "http://wiki.guildwars.com/index.php?title=Guild_Wars_Wiki:Admin_noticeboard&action=edit&reason=none&fakeaction=report&faketarget=" + addr, "Report", "rp-none", "Report user", ""); addPortletLink("note", "http://wiki.guildwars.com/index.php?title=Guild_Wars_Wiki:Admin_noticeboard&action=edit&reason=custom&fakeaction=report&faketarget=" + addr, "Custom", "rp-ask", "Report user (Custom message)", ""); addPortletLink("note", "http://wiki.guildwars.com/index.php?title=Guild_Wars_Wiki:Admin_noticeboard&action=edit&reason=vandal&fakeaction=report&faketarget=" + addr, "Report", "rp-vand", "Report user (Vandalism)", ""); addPortletLink("note", "http://wiki.guildwars.com/index.php?title=Guild_Wars_Wiki:Admin_noticeboard&action=edit&reason=ampersand&fakeaction=report&faketarget=" + addr, "Report", "rp-amp", "Report Ampersand bot (removing + signs)", ""); addPortletLink("note", "http://wiki.guildwars.com/index.php?title=Guild_Wars_Wiki:Admin_noticeboard&action=edit&reason=warned&fakeaction=report&faketarget=" + addr, "Warned", "rp-warn", "Report user (Ignored talk page warning)", ""); addPortletLink("note", "http://wiki.guildwars.com/index.php?title=Guild_Wars_Wiki:Admin_noticeboard&action=edit&reason=blank&fakeaction=report&faketarget=" + addr, "Blanking", "rp-blank", "Report user (Page blanking)", ""); addPortletLink("note", "http://wiki.guildwars.com/index.php?title=Guild_Wars_Wiki:Admin_noticeboard&action=edit&reason=proxy&fakeaction=report&faketarget=" + addr, "Proxy", "rp-proxy", "Report user (IP user abusing a proxy)", ""); addPortletLink("note", "http://wiki.guildwars.com/index.php?title=Guild_Wars_Wiki:Admin_noticeboard&action=edit&reason=tor&fakeaction=report&faketarget=" + addr, "Tor node", "rp-tor", "Report user (IP user abusing Tor)", "");

//Adds blocking link to previously created sysop menu if (AVTSysop) addPortletLink("sys", "http://wiki.guildwars.com/index.php?title=Special:Blockip?fakeaction=block?faketarget=" + addr, "Block user", "sys-block", "Block user from editing", "");

if (!/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/.test(addr)) return; // not an IP - these functions are for IP users only

var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; addlimenu(tabs, "lookup", "look" ); addPortletLink("look", "http://en.wikipedia.org/wiki/Special:Contributions/" + addr, "Wikipedia", "lo-wp", "Check Wikipedia contributions", ""); addPortletLink("look", "http://gw.gamewikis.org/wiki/Special:Contributions/" + addr, "GuildWiki", "lo-gw", "Check GuildWiki contributions", ""); addPortletLink("look", "http://www.dnsstuff.com/tools/whois.ch?ip=" + addr, "Whois", "lo-who", "Check WHOIS info", ""); addPortletLink("look", "http://www.robtex.com/rbls/" + addr + ".html", "RBLS", "lo-bl", "Check IP blacklists (RBLS)", ""); addPortletLink("look", "http://openrbl.org/client/#" + addr, "OpenRBL", "lo-or", "Check IP blacklists (OpenRBL)", ""); addPortletLink("look", "http://www.spamhaus.org/query/bl?ip=" + addr, "Spamhaus", "lo-sh", "Check IP blacklists (Spamhaus)", ""); addPortletLink("look", "http://dsbl.org/listing?" + addr, "DSBL", "lo-ds", "Check IP blacklists (DSBL)", ""); addPortletLink("look", "http://torlist.nullnetwork.net/ip.php?ip=" + addr, "Tor", "lo-tor", "Check for Tor exit node", ""); //Note: The tor link, while fairly extensive, does not have a complete list. However, that database is updated hourly =P }  return; }

function runAVT {  if (document.title.indexOf("Editing ") != -1) {     if (wgNamespaceNumber == 3) AVTtabs;

if (document.URL.lastIndexOf("&fakeaction") == -1) return;

if (document.URL.lastIndexOf("&fakeaction=report") != -1) {        AVTReport; return; }     if (document.URL.lastIndexOf("&fakeaction=warn") != -1) {        AVTWarning; return; }     // does the page exist? if (wgCurRevisionId == false) {        alert("The page has already been deleted."); return; }     if (document.URL.lastIndexOf("&fakeaction=del") != -1) {        AVTDeltag; return; }  }

//Sysop-only functions if (AVTSysop) {     if (document.URL.lastIndexOf("&fakeaction=block") != -1) {        AVTBlock; return; }     if (document.URL.lastIndexOf("&fakeaction=delete") != -1) {        AVTDelete; return; }  }

//Restore script based on Lorian's RevertTools (WP) //Adds a tab that will restore an old revision - this tab will only appear on a diff page. if (location.href.match(/diff=/)) { addPortletLink('p-cactions', "http://wiki.guildwars.com/index.php?title=" + _GET['title'] + "&action=edit&oldid=" + _GET['oldid'] + "&fakeaction=restore", 'restore', 'ca-rest', 'Restore old version'); }   else if (document.URL.lastIndexOf("&fakeaction=restore") != -1) {     var f = document.editform; f.wpSummary.value = "Restoring page to version " + _GET['oldid'] + " - AVT"; f.wpSave.click; return; }  //End restore script

//Create additional tabs AVTtabs; } addOnloadHook(runAVT); //