User:Veinor/csd.js

Source: Wikipedia, the free encyclopedia.
<
User:Veinor
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<nowiki>
function checkDb() {
  if (document.getElementById("wpTextbox1") != null) {
    var hastag = document.getElementById("wpTextbox1").value.match(/\{\{((db-[^{]+)|deletedpage)\}\}/);
    var deleted = (document.getElementById("newarticletext") != null)
    var csdtagging = (document.URL.match(/Tagged%20for%20speedy%20deletion/) != null)
    if ((hastag || deleted) && csdtagging) {
     alert("Page already has CSD tag.");
     history.back();
  }
}
}
addOnloadHook(function() {
  if (document.title.indexOf("Editing ") != 0 && (document.URL.search(/\?/) == -1 || document.URL.search(/http:\/\/en.wikipedia.org\/w\/index.php\?title=/) != -1))  {
     mw.util.addPortletLink('p-cactions', "javascript:easyDb(0)", "db-", "ca-db0", "db-", "");
     mw.util.addPortletLink('p-cactions', "javascript:easyDb(1)", "db|", "ca-db1", "db|", "");

  }
});
function easyDb(n) {
  var db;
  if (n == 0) {db="db-";}
  if (n == 1) {db="db|";}
  var type = prompt("What is X in Template:" + db + "X ?");
  if (type == null || type == "") return;
  var currlocation = document.URL;
  document.location = document.URL + "?action=edit&autoedit=s/^/\\n{{" + db + type +  "}}\\n/&autosummary=Tagged for speedy deletion&autoclick=wpSave";
}

addOnloadHook(checkDb);
//</nowiki>