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. */           /***********************************************/            var pages = document.getElementById("sonicboom-input").value, page = pages.split(/\n/g), reason = document.getElementById("sonicboom-reason").value;

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

/*************************/               /* delstring: api query. */               /*************************/                var delstring = "action=delete&title=" + encodeURIComponent(page[i]) + "&reason=" + encodeURIComponent(reason) + "&format=json&token=" + encodeURIComponent(token);

/**********************************************/               /* @function: checks if page is a blank line. */               /* @function: checks name against regex. */               /**********************************************/                if (page[i] === '') { document.getElementById("sonicboom-output").value += "Finished!"; alert("Finished!"); document.getElementById("sonicboom-input").value = ""; return; } else if (regex.test(page[i])) { document.getElementById("sonicboom-output").value += page[i] + ": 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 += "" + page[i] + ": Deleted\n"; } else { document.getElementById("sinicboom-output").value += "" + page[i] + ": Error\n"; }                       } else { document.getElementById("sinicboom-output").value += "" + page[i] + ": Error\n"; }                   };                }                socket.open("POST", "/api.php", true); socket.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); socket.send(delstring); }       });    } }(this.mediaWiki));