User:Animum/massdelete.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
function doMassDelete() {
document.getElementById("wpMassDeleteSubmit").disabled = true;
var articles = document.getElementById("wpMassDeletePages").value.split("\n");
for(i=0;i<articles.length;i++) {
var article = articles[i];
if(article.length > 0) {
var req = new XMLHttpRequest();
req.open("GET", wgScriptPath + "/api.php?format=json&action=query&prop=info&intoken=delete&titles=" + article, false);
req.send(null);
var response = eval("(" + req.responseText + ")").query.pages;
for(var index in response) {
var info = response[index];
var deletetoken = info.deletetoken;
var postdata = "wpReason=" + document.getElementById("wpMassDeleteReason").value
+ "&wpEditToken=" + encodeURIComponent(deletetoken);
var req = new XMLHttpRequest();
req.open("POST", wgScript + "?title=" + article + "&action=delete", false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", postdata.length);
req.send(postdata);
}
}
if(!articles[i+1]) {
document.getElementById("wpMassDeleteSubmit").value = "Done!";
}
}
}
function massdeleteform() {
var bodyContent = (skin == "cologneblue" ? "article" : "bodyContent");
document.getElementsByTagName("h1")[0].textContent = "Animum's mass-deletion tool";
document.title = "Animum's mass-deletion tool - Wikipedia, the free encyclopedia";
document.getElementById(bodyContent).innerHTML = '<h3 id="siteSub">From Wikipedia, the free encyclopedia</h3><br /><br />'
+ '<b>If you screw around with this tool, it\'s <i>your</i> fault, not mine, bucko.</b>'
+ '<br /><br />'
+ '<form id="wpMassDelete" name="wpMassDelete">'
+ 'Pages to delete (one on each line, please):<br />'
+ '<textarea tabindex="1" accesskey="," name="wpMassDeletePages" id="wpMassDeletePages" rows="10" cols="80"></textarea>'
+ '<br /><br />'
+ 'Reason: '
+ '<input type="text" id="wpMassDeleteReason" name="wpMassDeleteReason" maxlength="255" />'
+ '<br /><br />'
+ '<input type="button" id="wpMassDeleteSubmit" name="wpMassDeleteSubmit" value="Delete" onclick="doMassDelete()" />'
+ '</form>';
}
addOnloadHook(function() {
if(wgNamespaceNumber == -1 && wgPageName == "Special:Massdelete" && RegExp("sysop", "i").test(wgUserGroups)) {
massdeleteform();
}
});