User:Prince(ss) Platinum/Sonicboom.js

/*********************************/ /*         Sonicboom            */ /*    A batch delete script     */ /* Written by: Benjamin Williams */ /*       License: GPL v2        */ /*********************************/ (function (mw) {

/********************************/   /* token: delete token. */   /* page: page to load on. */   /* regex: bad character regex. */   /* form: form html. */   /********************************/    var token = mw.user.tokens.get("editToken"), page = "Special:Sonicboom", regex = /(\#|<|>|\[|\]|\{|\}|\|)/, form = ' Sonicboom Pages: 

Reason: 

Ouput: 

Start  ';

/*********************************************************/   /* @function: compares page names to see if it can load. */   /*********************************************************/    if (mw.config.get("wgPageName") == page) {

/**********************************/       /* @function: add form to page. */       /* @function: add event listener. */       /**********************************/        document.getElementById("WikiaArticle").innerHTML = form; document.getElementById("sonicboom-start").addEventListener("click", function {

/***********************************************/           /* pages/page: get and split textarea content. */           /* reason: get reason from input. */           /* delstring: api query. */           /***********************************************/            var pages = document.getElementById("sonicboom-input").value, page = pages.split(/\n/g), reason = document.getElementById("sonicboom-reason").value, delstring = "action=delete&title=" + encodeURIComponent(pagename) + "&reason=" + encodeURIComponent(reason) + "&format=json&token=" + encodeURIComponent(token);

/*******************************************************/           /* @function: perform checks on each page and post it. */           /*******************************************************/            for (var i = 0; i < page.length; i++) {

/********************************/               /* pagename: current page name. */               /********************************/                var pagename = page[i];

/**********************************************/               /* @function: checks if page is a blank line. */               /* @function: checks name against regex. */               /**********************************************/                if (name === '') { document.getElementById("sonicboom-output").value += "Finished!"; document.getElementById("sonicboom-input").value = ""; return; } else if (regex.test(name)) { document.getElementById("sonicboom-output").value += pagename + ": Skipped (badchar)\n"; continue; } else {

/***************************************/                   /* socket: creates new XMLHttpRequest. */                   /***************************************/                    var socket = new XMLHttpRequest;

socket.onreadystatechange = function { if (this.readyState == 4 && this.status == 200) { if (this.responseText !== "Error") { document.getElementById("sonicboom-output").value += pagename + ": Deleted\n"; } else { document.getElementById("sinicboom-output").value += pagename + ": Error\n"; }                       } else { document.getElementById("sinicboom-output").value += pagename + ": Error\n"; }                   };                }                socket.open("POST", "/api.php", true); socket.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); socket.send(delstring); }       });    } }(this.mediaWiki));