Jump to content

User:Anonlta/monobook.js

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Anonlta (talk | contribs) at 14:26, 3 October 2008. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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.
importScript('User:TheJosh/Scripts/NewPagePatrol.js');

//custom DB script modified from [[Wikipedia:WikiProject User scripts/Scripts/Easy db]]
var csdDeleteForm = {
  FillSelect:function(sel, arr){
    for(var i=0;i<arr.length;i++){
      var opt = new Option(arr[i].display, arr[i].value);
      // catches stupid IE error
      if(opt.innerHTML != arr[i].display){
        opt.innerHTML = arr[i].display;
      }
      if (arr[i].value == ""){
        opt.style.color = "gray";
        opt.disabled = true;
      }
      sel.appendChild(opt);
    }
    return true;
  },
  ValueArray:[
    {"value":"","display":"General"},
    {"value":"G1","display":"G1 - Nonsense"},
    {"value":"G2","display":"G2 - Test Pages"},
    {"value":"G3+vandalism","display":"G3 - Pure Vandalism"},
    {"value":"G3+pagemove","display":"G3 - Nonsense Redirect"},
    {"value":"G4","display":"G4 - Recreated Deleted"},
    {"value":"G5+banned+Name of banned user","display":"G5 - Banned User"},
    {"value":"G6+histmerge+Page to merge history from","display":"G6 - History Merge"},
    {"value":"G6+move+Target location+Reason for move","display":"G6 - Move"},
    {"value":"G6+copypaste+otherpage=?","display":"G6 - Copypaste Cleanup"},
    {"value":"G6+xfd","display":"G6 - Marked for Deletion"},
    {"value":"G6+maintenance","display":"G6 - Housekeeping"},
    {"value":"G7+author","display":"G7 - Author Request"},
    {"value":"G7+blanked","display":"G7 - Author Blanked"},
    {"value":"G8+talk","display":"G8 - Orphaned Talk Page"},
    {"value":"G8+subpage","display":"G8 - Orphaned Subpage"},
    {"value":"G8+imagepage","display":"G8 - Orphaned Image Page"},
    {"value":"G10","display":"G10 - Attack Pages"},
    {"value":"G11","display":"G11 - Advertising"},
    {"value":"G12+copyvio+url=?","display":"G12 - Copyright"},
    {"value":"","display":"Articles"},
    {"value":"A1","display":"A1 - No Context"},
    {"value":"A2","display":"A2 - Foreign Language"},
    {"value":"A3","display":"A3 - No Content"},
    {"value":"A5","display":"A5 - Transwikied"},
    {"value":"A7+bio","display":"A7 - Unremarkable Bio"},
    {"value":"A7+person","display":"A7 - Unremarkable Person"},
    {"value":"A7+band","display":"A7 - Unremarkable Band"},
    {"value":"A7+club","display":"A7 - Unremarkable Group"},
    {"value":"A7+inc","display":"A7 - Unremarkable Corporation"},
    {"value":"A7+web","display":"A7 - Unremarkable Website"},
    {"value":"","display":"Redirects"},
    {"value":"R1","display":"R1 - Bad Target"},
    {"value":"R2","display":"R2 - User Page Redirect"},
    {"value":"R3","display":"R3 - Implausible Typo"},
    {"value":"","display":"Images"},
    {"value":"I1+i1+replacement image.ext","display":"I1 - Redundant"},
    {"value":"I2","display":"I2 - Corrupt/Empty"},
    {"value":"I3","display":"I3 - Improper License"},
    {"value":"I4","display":"I4 - Lack of License"},
    {"value":"I5","display":"I5 - Unused Unfree"},
    {"value":"I6","display":"I6 - No Fair Use"},
    {"value":"I7","display":"I7 - Invalid Fair Use"},
    {"value":"I8+i8+Name on commons.ext","display":"I8 - On Commons"},
    {"value":"I9+imgcopyvio+url=?","display":"I9 - Copyright"},
    {"value":"I10","display":"I10 - Bad File Type"},
    {"value":"","display":"Categories"},
    {"value":"C1","display":"C1 - Empty"},
    {"value":"C2","display":"C2 - Speedy Rename"},
    {"value":"C3","display":"C3 - Template Deleted"},
    {"value":"","display":"User Pages"},
    {"value":"U1","display":"U1 - User Request"},
    {"value":"U2","display":"U2 - No User"},
    {"value":"U3","display":"U3 - Fair Use Gallery"},
    {"value":"","display":"Templates"},
    {"value":"T1","display":"T1 - Divisive"},
    {"value":"T2","display":"T2 - Policy"},
    {"value":"T3+t3|11:40, 3 October 2008 (UTC)+Other template name","display":"T3 - Duplicate or Inferior"},
    {"value":"","display":"Portals"},
    {"value":"P2","display":"P2 - Underpopulated"}
    ]
}

function csdShowBox(){
  //Create Box
  var obj = document.editform;

  var csdOuter = document.createElement('div');
  csdOuter.align = "center";
  var csdContainer = document.createElement('div');
  csdContainer.id = "dbContainer";
  csdContainer.align="center";
  csdContainer.style.width = "250px";
  csdContainer.style.backgroundColor = "#fee";
  csdContainer.style.border = "2px solid #b22222";

  var csdHeader = document.createElement('h4');
  csdHeader.innerHTML = "Delete because:";
  csdContainer.appendChild(csdHeader);

  var csdOpt1 = document.createElement('button');
  csdOpt1.id = "csdOption1";
  csdOpt1.innerHTML = "CSD";
  csdOpt1.style.marginBottom = "5px";
  csdOpt1.style.marginRight = "20px";
  csdOpt1.style.width = "100px";
  csdOpt1.onclick = csdRedPill;
  csdContainer.appendChild(csdOpt1);

  var csdOpt2 = document.createElement('button');
  csdOpt2.id = "csdOption2";
  csdOpt2.innerHTML = "Reason";
  csdOpt2.style.marginBottom = "5px";
  csdOpt2.style.width = "100px";
  csdOpt2.onclick = csdBluePill;
  csdContainer.appendChild(csdOpt2);

  //Add box
  csdOuter.appendChild(csdContainer);
  obj.parentNode.insertBefore(csdOuter,obj);
}

addOnloadHook(csdShowBox); //debug

function csdRedPill() {
  //Delete by CSD
  var csdContainer = document.getElementById("dbContainer");
  var button1 = document.getElementById("csdOption1");
  var button2 = document.getElementById("csdOption2");
  button1.parentNode.removeChild(button1);
  button2.parentNode.removeChild(button2);

  var sel = document.createElement('select');
  csdDeleteForm.FillSelect(sel, csdDeleteForm.ValueArray);
  sel.name = "csdOptions";
  sel.id = "csdOptions";
  sel.style.marginLeft = "10px";
  sel.style.marginBottom = "8px";
  csdContainer.appendChild(sel);

  var csdNewline = document.createElement('br');
  csdContainer.appendChild(csdNewline);

  var csdSubmit = document.createElement('button');
  csdSubmit.innerHTML = "Delete";
  csdSubmit.style.marginBottom = "5px";
  csdSubmit.onclick = csdSubmitAction;
  csdContainer.appendChild(csdSubmit);  
}

function csdBluePill() {
  //Delete by reason
  var csdContainer = document.getElementById("dbContainer");
  var button1 = document.getElementById("csdOption1");
  var button2 = document.getElementById("csdOption2");
  button1.parentNode.removeChild(button1);
  button2.parentNode.removeChild(button2);

  var csdText = document.createElement('input');
  csdText.type = "text";
  csdText.size = "25";
  csdText.name = "dbReason";
  csdText.id = "dbReason";
  csdContainer.appendChild(csdText);

  var csdNewline = document.createElement('br');
  csdContainer.appendChild(csdNewline);

  var csdSubmit = document.createElement('button');
  csdSubmit.innerHTML = "Delete";
  csdSubmit.style.marginBottom = "5px";
  csdSubmit.onclick = csdSubmitReason;
  csdContainer.appendChild(csdSubmit); 
}

function csdSubmitAction() {
  var csdInput = document.getElementById('csdOptions').value.split("+");
  var csdCat = csdInput[0];
  var csdType = csdInput[1];
  if (!csdType) { csdType = csdCat.toLowerCase(); }

  //if template requires inputs, ask for them
  if (csdInput.length > 2) {
    var csdExt = "";
    var csdTemp = null;
    for(var i=2;i<csdInput.length;i++){
      csdTemp = prompt(csdInput[i]);
      if (csdTemp!=null && csdTemp!="") {
        csdExt = csdExt.concat("|",csdTemp);
      }
    }
    csdType = csdType.concat(csdExt);
  }

  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{db-" + csdType + "}}\n" + t.value;
  f.wpSummary.value = "JS: Requesting speedy deletion ([[WP:CSD#" + csdCat + "|CSD " + csdCat.toUpperCase() + "]])";
  f.wpSave.click();
  return;
}

function csdSubmitReason() {
  var type = document.getElementById("dbReason").value;
  if (type == "")
    return;
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{db|" + type + "}}\n" + t.value;
  f.wpSummary.value = "JS: Requesting speedy deletion";
  f.wpSave.click();
  return;
}

addOnloadHook(function()
{
  //check if called from deletion request
  if (document.URL.lastIndexOf("&easydb") != -1)
  {
    if (document.title.indexOf("Editing ") == -1)
      return;
    // does the page exist?
    if (wgCurRevisionId == false)
    {
      alert("The page has already been deleted.");
      return;
    }
    csdShowBox();
  }
  if (wgCanonicalNamespace == "Special")
    return;

  addPortletLink("p-cactions", "javascript:easyDb()", "easy db", "ca-db", "Request speedy deletion", "");
});
 
function easyDb()
{
  var title = wgPageName.replace("&", "%26").replace("+", "%2B");
  location.assign("/w/index.php?&action=edit&easydb&title=" + title);
}
//end of script