User:Awesome Aasim/oneclickdelete.js

//

if (mw.config.get("wgNamespaceNumber") >= 0 && mw.config.get("wgIsProbablyEditable")) {

var oneClickDelete = {};

$(document).ready(function() {

oneClickDelete.addReason = function(reason, tag) {

oneClickDelete.reasons.push([tag, reason]);

//oneClickDelete.tag[reason] = tag;

};

oneClickDelete.delete = function(reason, tag) {

console.log("Getting token...");

$.get(mw.config.get("wgScriptPath") + "/api.php", {

"action": "query",

"meta": "tokens",

"type": "csrf",

"format": "json"

}).done(function(token) {

if (token.error) {

mw.notify($("" + token.error.info + ""));

} else {

var temp = tag.substring(3, 6);

if (temp.toLowerCase() != "st:" && temp.toLowerCase() != "c1") {

$.post(mw.config.get("wgScriptPath") + '/api.php', {

"action": "delete",

"format": "json",

"title": mw.config.get("wgPageName"),

"reason": reason + " (One Click Deletion Script)",

"token": token.query.tokens.csrftoken

}).done(function(editresult) {

if (editresult.error) {

mw.notify($("" + editresult.error.info + ""));

} else {

location.href = "/wiki/" + mw.config.get("wgPageName");

}

}).fail(function(editresult) {

mw.notify("" + editresult + "");

});

} else {

oneClickDelete.addTag(tag);

}

}

}).fail(function(token) {

mw.notify($("" + token + ""));

});

};

oneClickDelete.addTag = function(reason) {

if (reason) {

console.log("Getting wikitext...");

$.get(mw.config.get("wgScriptPath") + "/api.php", {

"action": "parse",

"prop": "wikitext",

"page": mw.config.get("wgPageName"),

"format": "json"

}).done(function(result) {

if (result.error) {

mw.notify($("" + result.error.info + ""));

} else if (result.parse.wikitext["*"].toLowerCase().substring(0, 100).includes("{{db") || result.parse.wikitext["*"].toLowerCase().substring(0, 100).includes("{{db")) {

mw.notify($("" + "Page already tagged for speedy deletion. Please manually edit the tag instead of using this script." + ""));

} else {

console.log("Getting token...");

$.get(mw.config.get("wgScriptPath") + "/api.php", {

"action": "query",

"meta": "tokens",

"type": "csrf",

"format": "json"

}).done(function(token) {

if (token.error) {

mw.notify($("" + token.error.info + ""));

} else {

console.log("Building wikitext and saving...");

var newwikitext = result.parse.wikitext["*"];

if (reason == "db-g10") {

newwikitext = "{{" + reason + "}}";

} else {

if (reason != "subst:void") {

newwikitext = "{{" + reason + "}}" + newwikitext;

} else {

newwikitext = "{{" + reason + "}}" + newwikitext;

}

}

$.post(mw.config.get("wgScriptPath") + '/api.php', {

"action": "edit",

"format": "json",

"title": mw.config.get("wgPageName"),

"text": newwikitext,

"summary": "Adding {{" + reason + "}} (One Click Deletion Script)",

"token": token.query.tokens.csrftoken

}).done(function(editresult) {

if (editresult.error) {

mw.notify($("" + editresult.error.info + ""));

} else {

location.href = "/wiki/" + mw.config.get("wgPageName");

}

}).fail(function(editresult) {

mw.notify("" + editresult + "");

});

}

}).fail(function(token) {

mw.notify($("" + token + ""));

});

}

}).fail(function(result) {

mw.notify($("" + result + ""));

});

}

};

oneClickDelete.select = $('