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 = $(''); oneClickDelete.el = $(' '); $.get(mw.config.get("wgScriptPath") + "/api.php", {			"action": "parse",			"prop": "wikitext",			"format": "json",			"page": mw.config.get("wgPageName")		}).done(function(result) {			if (!result.error) {				// reasons begin				oneClickDelete.reasons = [];				// general				oneClickDelete.addReason("General", "-");				oneClickDelete.addReason("G1: Patent nonsense", "db-g1");				if (mw.config.get("wgNamespaceNumber") != 2) {					oneClickDelete.addReason("G2: Test page", "db-g2");				}				oneClickDelete.addReason("G3: Pure vandalism", "db-g3");				oneClickDelete.addReason("G3: Blatant hoax", "db-hoax");				oneClickDelete.addReason("G4: Recreation of a page deleted per a deletion discussion", "db-g4");				oneClickDelete.addReason("G5: Block/ban evasion", "db-g5");				oneClickDelete.addReason("G6: Page created in error", "db-error"); oneClickDelete.addReason("G7: Author request", "db-g7"); oneClickDelete.addReason("G8: Dependent on non-existent page", "db-g8"); if (result.parse.wikitext["*"].toLowerCase.substring(0, "#redirect".length).match(/.*\#redirect.*/g)) { oneClickDelete.addReason("G8: Broken redirect", "db-redirnone"); } else { if (mw.config.get("wgNamespaceNumber") % 2 == 1) { oneClickDelete.addReason("G8: Talk page of non-existent page", "db-talk"); }					if (mw.config.get("wgPageName").includes("/") && mw.config.get("wgNamespaceNumber") != 0) { oneClickDelete.addReason("G8: Subpage of non-existent page", "db-subpage"); }					if (mw.config.get("wgNamespaceNumber") == 6) { oneClickDelete.addReason("G8: File description page with no corresponding file", "db-imagepage"); }					if (mw.config.get("wgNamespaceNumber") == 14) { oneClickDelete.addReason("G8: Category populated by deleted/retargeted template", "db-templatecat"); }				}				oneClickDelete.addReason("G10: Attack page", "db-g10"); oneClickDelete.addReason("G11: Spam/unambiguous advertising", "db-g11"); if (mw.config.get("wgNamespaceNumber") == 2) { oneClickDelete.addReason("G11: Spam user page", "db-spamuser"); }				oneClickDelete.addReason("G13: Abandoned drafts/AfC submissions", "db-g13"); oneClickDelete.addReason("G14: Unnecessary disambiguation", "db-g14"); if (result.parse.wikitext["*"].toLowerCase.substring(0, "#redirect".length).match(/.*\#redirect.*/g)) { // redirect oneClickDelete.addReason("Redirects", "-"); oneClickDelete.addReason('R2: Inappropriate cross-namespace redirect', 'db-r2'); oneClickDelete.addReason('R3: Implausible typo', 'db-r3'); if (mw.config.get("wgNamespaceNumber") == 6) { oneClickDelete.addReason('Redirect with Wikimedia Commons match', 'db-r4'); }				} else { if (mw.config.get("wgNamespaceNumber") == 0) { // article oneClickDelete.addReason("Articles", "-"); oneClickDelete.addReason('A1: No context', 'db-a1'); oneClickDelete.addReason('A3: No content', 'db-a3'); oneClickDelete.addReason('A5: Transwikied', 'db-a5'); //oneClickDelete.addReason('A7: No indication of importance (people, animals, organizations, web content, events)', 'db-a7'); oneClickDelete.addReason('A7: No indication of importance (person)', 'db-person'); oneClickDelete.addReason('A7: No indication of importance (band)', 'db-band'); oneClickDelete.addReason('A7: No indication of importance (club)', 'db-club'); oneClickDelete.addReason('A7: No indication of importance (organization)', 'db-inc'); oneClickDelete.addReason('A7: No indication of importance (web content)', 'db-web'); oneClickDelete.addReason('A7: No indication of importance (animal)', 'db-animal'); oneClickDelete.addReason('A7: No indication of importance (event)', 'db-event'); oneClickDelete.addReason('A9: No indication of importance (music recordings)', 'db-a9'); oneClickDelete.addReason('A11: Obviously invented', 'db-a11'); oneClickDelete.addReason('Unsourced biography', 'subst:prod blp'); }					if (mw.config.get("wgNamespaceNumber") == 6) { // files oneClickDelete.addReason("Files", "-"); oneClickDelete.addReason('F2: Corrupt file', 'db-f2'); oneClickDelete.addReason('F3: Improper license', 'db-f3'); oneClickDelete.addReason('No source', 'subst:nsd'); oneClickDelete.addReason('No license', 'subst:nld'); oneClickDelete.addReason('No source or license', 'subst:nsdnld'); oneClickDelete.addReason('F5: Non-free image used in now-deleted article', 'db-f5'); oneClickDelete.addReason('Orphaned non-free file', 'subst:orfud'); oneClickDelete.addReason('Orphaned non-free revisions', 'subst:orfurrev'); oneClickDelete.addReason('Missing non-free use rationale', 'subst:nrd'); oneClickDelete.addReason('F7: Obviously invalid fair use claim', 'db-f7'); oneClickDelete.addReason('Replacable with free images', 'subst:rfu'); oneClickDelete.addReason('Disputed fair use rationale', 'subst:dfu'); oneClickDelete.addReason('F8: File available on Commons', 'db-f8'); oneClickDelete.addReason('F10: Useless non-media file', 'db-f10'); oneClickDelete.addReason('No evidence of permission', 'subst:npd'); }					if (mw.config.get("wgNamespaceNumber") == 14) { // categories oneClickDelete.addReason("Categories", "-"); oneClickDelete.addReason('C1: Empty category', 'db-c1'); }					if (mw.config.get("wgNamespaceNumber") == 2 || mw.config.get("wgNamespaceNumber") == 3) { // user pages oneClickDelete.addReason("User pages", "-"); oneClickDelete.addReason('U1: User request', 'db-u1'); oneClickDelete.addReason('U2: Nonexistent user', 'db-u2'); oneClickDelete.addReason('U3: Non-free gallery', 'db-u3'); oneClickDelete.addReason('U5: Misuse of Wikipedia as a web host', 'db-u5'); }					if (mw.config.get("wgNamespaceNumber") == 100) { // portals oneClickDelete.addReason("Portals", "-"); oneClickDelete.addReason('P1: Meets article criteria for speedy deletion A1', 'db-p1|a1'); oneClickDelete.addReason('P1: Meets article criteria for speedy deletion A3', 'db-p1|a3'); oneClickDelete.addReason('P1: Meets article criteria for speedy deletion A5', 'db-p1|a5'); oneClickDelete.addReason('P1: Meets article criteria for speedy deletion A7', 'db-p1|a7'); oneClickDelete.addReason('P1: Meets article criteria for speedy deletion A9', 'db-p1|a9'); oneClickDelete.addReason('P1: Meets article criteria for speedy deletion A11', 'db-p1|a11'); oneClickDelete.addReason('P2: Underpopulated portal', 'db-p2'); }				}				oneClickDelete.select.append($(' ').prop('disabled', true).prop('selected', true).text("OCD...")); oneClickDelete.select.append($(' ').attr('value', 'subst:void').text("Cancel")); oneClickDelete.select.change(function(e) {					//debugger;					oneClickDelete.select.prop("disabled", true);					if (mw.config.get("wgUserGroups").includes("sysop")) {						oneClickDelete.delete($("#qcsd-dropdown option:selected").text, $("#qcsd-dropdown").val);					} else {						oneClickDelete.addTag($("#qcsd-dropdown").val);					}				}); oneClickDelete.reasons.forEach(function(r) {					if (r[0] == "-") {						oneClickDelete.select.append($(' ').prop('disabled', true).text(r[1]));					} else {						oneClickDelete.select.append($(' ').attr('value', r[0]).text("\xA0\xA0" + r[1]));					}				}); oneClickDelete.el.appendTo("#siteNotice"); if (mw.config.get("skin") != "minerva") { oneClickDelete.el.css({"float": "right", "margin-left": "10px"}); }				oneClickDelete.select.appendTo("#qcsd"); }		}).fail(function(result) { });	}); } //