User:Animum/easyblock.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

/**********************************
 *  Easyblock v1.3                *
 **********************************
 *  By Animum                     *
 ********************************************
 *  INSTALLATION INSTRUCTIONS:              *
 *                                          *
  //[[User:Animum/easyblock.js]]           
  importScript('User:Animum/easyblock.js') 
 *******************************************/
 
/*******************************
 *  Handy-dandy block script   *
 *******************************
 *  Code taken from select     *
 *  scripts made by DerHexer   *
 *  and Voice of All with      *
 *  some code by Animum.       *
 *******************************
 *  This script has only been  *
 *  tested in Firefox. It may  *
 *  not work in other          *
 *  browsers.                  *
 *******************************/
 
/* Libraries that support this script (with the exception of twinklefluff.js) */
importScript('User:Animum/urlparameters.js');
importScript('User:AzaToth/twinklefluff.js');
importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css');
function addlilink(tabs, url, name, id, title, key){
    var na = document.createElement('a');
    na.onclick = function() { location.href = url };
    na.appendChild(document.createTextNode(name));
    na.style.cssText = 'cursor:pointer';
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    if(id)
    {
        if(key && title)
        {
            ta[id] = [key, title];
        }
        else if(key)
        {
            ta[id] = [key, ''];
        }
        else if(title)
        {
            ta[id] = ['', title];
        }
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}
 
function addlimenu(tabs, name, id, href, position) {
    var na, mn;
    var li;
 
    if (!id)  id = name;
 
    na = document.createElement("a");
    na.appendChild(document.createTextNode(name));
    na.onclick = href;
    na.style.cssText = 'cursor:pointer';
    mn = document.createElement("ul");
    li = document.createElement("li");
    li.appendChild(na);
    li.appendChild(mn);
    if (id) li.id = id;
    li.className = 'tabmenu';
 
    if (position) {
        tabs.insertBefore(li, position);
    } else {
        tabs.appendChild(li);
    }
 
    return mn;  // useful because it gives us the <ul> to add <li>s to
}
/* End of library section */
 
var Animum_testing = 0;
 
addOnloadHook(function() {
if(wgNamespaceNumber==2 || wgNamespaceNumber==3) {
 if(document.title.indexOf('/') != -1) {
  var lemma = wgTitle.split('/')[0];
 } else {
  var lemma = wgTitle;
 }
}
 
/* Diffs can be so temperamental */
if (UrlParameters["diff"] > "") {
var ntitle = getElementsByClassName( document.getElementById('bodyContent'), 'td' , 'diff-ntitle' )[0];
 var lemma = ntitle.getElementsByTagName("a")[(ntitle.getElementsByTagName('a')[3].firstChild.nodeValue == 'Current revision' ? 6 : 3)].firstChild.nodeValue;
}
 
if(wgPageName=="Special:IPBlockList" && window.location.href.indexOf("&action=success&successip=") != -1) {
 var lemma = document.getElementById("contentSub").getElementsByTagName("a")[0].firstChild.nodeValue;
}
 
if (wgPageName=="Special:Contributions") {
 if(window.location.href.split("Contributions/")[1] != undefined) {
  var lemma = window.location.href.split("Contributions/")[1];
 } else if(UrlParameters["target"] != undefined) {
  var lemma = UrlParameters["target"];
   } else if(window.location.href.split("Contributions%2F")[1] != undefined) {
      var lemma = window.location.href.split("Contributions%2F")[1];
     }
}
 
if(wgPageName=="Special:BlockIP") {
 if(window.location.href.indexOf("&action=success") == -1) {
  var lemma = document.forms["blockip"].elements["wpBlockAddress"].value;
 } else {
  var lemma = UrlParameters["ip"];
 }
}
   if (wgPageName == "Special:BlockIP") {
    if(UrlParameters["wpBlockReason"] > "" && UrlParameters["wpBlockOther"] > "") {
     var ipBlocked = UrlParameters["title"].replace(/Special:BlockIP\//, '');
     var page;
     var reasonform = document.forms["blockip"].elements["wpBlockReason"].value;
      if(UrlParameters["wpBlockReason"] == "sockpuppet") {
        var sockof = prompt("Of whom is this user a sock puppet?");
         if(!sockof) return;
        document.forms["blockip"].elements["wpBlockReason"].value = "\[\[Wikipedia:Sock puppetry\|Sock puppet\]\] of \[\[User:" + sockof + "\|" + sockof + "\]\]";
         page = 'http://en.wikipedia.org/w/index.php?title=User_talk:' + ipBlocked + '&action=edit&template=6&sockof=' + sockof;
      }
      if(reasonform == "[[Wikipedia:Vandalism|Vandalism]]") {
        page = 'http://en.wikipedia.org/w/index.php?title=User_talk:' + ipBlocked + '&action=edit&template=1&duration=' + document.forms["blockip"].elements["wpBlockOther"].value.replace(/ /g, '%20');
      }
      if(reasonform == "{{uw-ublock}}") {
        page = 'http://en.wikipedia.org/w/index.php?title=User_talk:' + ipBlocked + '&action=edit&template=3';
      }
      if(reasonform == "{{uw-uhblock}}") {
        page = 'http://en.wikipedia.org/w/index.php?title=User_talk:' + ipBlocked + '&action=edit&template=4';
      }
      if(reasonform == "[[Wikipedia:Vandalism|Vandalism]]-only account") {
        page = 'http://en.wikipedia.org/w/index.php?title=User_talk:' + ipBlocked + '&action=edit&template=2';
      }
      addition = new Date(); 
      addition = new Date(addition.getTime() + 1000*20);
      document.cookie = 'blocknoticeurl=' + page + '; path=/; expires=' + addition.toGMTString() + ';'; //Store the URL in a cookie
     if (UrlParameters["wpBlockOther"] == 'indefinite') {
         if (reasonform != '{{uw-ublock}}') {
           document.forms["blockip"].elements["wpEmailBan"].checked = false;
           document.forms["blockip"].elements["wpCreateAccount"].checked = true;
           document.forms["blockip"].elements["wpEnableAutoblock"].checked = true;
         } else if(reasonform == '{{uw-uhblock}}') {
           document.forms["blockip"].elements["wpCreateAccount"].checked = true;
           document.forms["blockip"].elements["wpEnableAutoblock"].checked = true;
           document.forms["blockip"].elements["wpEmailBan"].checked = false;
         } else {
           document.getElementById("wpCreateAccount").checked = false;
           document.getElementById("wpEnableAutoblock").checked = false;
           document.getElementById("wpEmailBan").checked = false;
         }
     } else { 
           document.forms["blockip"].elements["wpEmailBan"].checked = false;
           document.forms["blockip"].elements["wpCreateAccount"].checked = true;
           document.forms["blockip"].elements["wpEnableAutoblock"].checked = true;
       }
    }
    if(document.getElementById("contentSub").innerHTML == "Block successful") {
     var cookies = document.cookie.split(';');
     for (i=0; i<cookies.length; i++) {
      var cookienames = cookies[i].split('=')[0];
      if(cookienames.indexOf('blocknoticeurl') != -1) {
       addnavbox_link(cookies[i].split("blocknoticeurl=")[1], 'Auto-warn', 'n-autowarn');
      } 
     }
    }
   }
 
    if (UrlParameters["template"] > '') {
     document.forms["editform"].wpMinoredit.value = 1;
     if (UrlParameters["template"] == 1) {
       document.editform.wpSummary.value = "Due to recent \[\[Wikipedia\:Vandalism\|vandalism\]\] from this " + (wgTitle.search(/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/) != -1 ? "IP address" : "account") + ", it has been blocked for " + decodeURIComponent(UrlParameters["duration"]) + ".";
       document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value + "\n\{\{subst\:uw-vblock\|time=" + decodeURIComponent(UrlParameters["duration"]) + "\|subst\=subst\:\|sig\=y\}\}";
       document.forms["editform"].wpSave.click();
     } if (UrlParameters["template"] == 2) {
       document.forms["editform"].wpSummary.value = "You have been blocked indefinitely because your account has been used only for \[\[Wikipedia\:Vandalism\|vandalism\]\].";
       document.forms["editform"].wpTextbox1.value += "\n\{\{subst\:uw-voablock\|subst\=subst\:\|sig\=y\}\}";
       document.forms["editform"].wpSave.click();
       location.href = "http://en.wikipedia.org/w/index.php?title=User:" + wgTitle + "&action=edit&template=5";
     } if (UrlParameters["template"] == 3) {
       document.forms["editform"].wpSummary.value = "You have been blocked for a violation of the \[\[Wikipedia\:Username policy\|username policy\]\].";
       document.forms["editform"].wpTextbox1.value += (document.forms["editform"].wpTextbox1.value.length < 1 ? "" : "\n") + "\{\{subst:uw-ublock\|sig\=y\|subst\=subst\:\}\}";
       document.forms["editform"].wpSave.click();
     } if (UrlParameters["template"] == 4) {
       document.forms["editform"].wpSummary.value = "You have been blocked for a violation of the \[\[Wikipedia\:Username policy\|username policy\]\].";
       document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value + (document.forms["editform"].wpTextbox1.value.length < 1 ? "" : "\n") + "\{\{subst:uw-uhblock\|sig\=y\|subst\=subst\:\}\}";
       document.forms["editform"].wpSave.click();
     } if (UrlParameters["template"] == 5) {
       document.forms["editform"].wpSummary.value = "You have been blocked indefinitely from editing Wikipedia.";
       document.forms["editform"].wpTextbox1.value = "\{\{indefblockeduser\}\}";
       document.forms["editform"].wpSave.click();
     } if (UrlParameters["template"] == 6) {
       document.forms["editform"].wpSummary.value = "You are a sockpuppet or are suspected to be a sockpuppet of the blocked or banned \[\[User\:" + decodeURIComponent(UrlParameters["sockof"]) + "\|" + decodeURIComponent(UrlParameters["sockof"]) + "\]\] and have been blocked indefinitely.";
       document.forms["editform"].wpTextbox1.value += "\n\{\{subst\:sockblock\|" + decodeURIComponent(UrlParameters["sockof"]) + "\}\}";
       document.forms["editform"].wpSave.click();
       location.href = "http://en.wikipedia.org/w/index.php?title=User:" + wgTitle + "&action=edit&template=7&sockof=" + UrlParameters["sockof"];
    } if (UrlParameters["template"] == 7) {
       document.forms["editform"].wpSummary.value = "You are a sockpuppet or are suspected to be a sockpuppet of the blocked or banned \[\[User\:" + decodeURIComponent(UrlParameters["sockof"]) + "\|" + decodeURIComponent(UrlParameters["sockof"]) + "\]\] and have been blocked indefinitely.";
       document.forms["editform"].wpTextbox1.value = "\{\{sockpuppet\|" + decodeURIComponent(UrlParameters["sockof"]) + "\|blocked\}\}";
       document.forms["editform"].wpSave.click();
    }
   }
 
  if(wgNamespaceNumber==2 || wgNamespaceNumber==3 || UrlParameters["diff"] > "" ||wgPageName=="Special:Contributions" || wgPageName=="Special:BlockIP" || window.location.href.indexOf("Special:IPBlockList&action=success&successip=") != -1) {
    if((wgPageName == "Special:BlockIP" && window.location.href.indexOf("&action=success") != -1) || (wgPageName == "Special:BlockIP" && document.forms["blockip"].elements["wpBlockAddress"].value.length == 0)) {
      return;
    } else {
        var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
        addlimenu(tabs, 'block', 'warnfunc', '');
        var warnfunc = document.getElementById('warnfunc').getElementsByTagName('ul')[0];
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=24+hours&wpBlockReason=%5B%5BWikipedia%3AVandalism%7CVandalism%5D%5D", 'V+24 hours', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=31+hours&wpBlockReason=%5B%5BWikipedia%3AVandalism%7CVandalism%5D%5D", 'V+31 hours', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=3+days&wpBlockReason=%5B%5BWikipedia%3AVandalism%7CVandalism%5D%5D", 'V+3 days', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=1+week&wpBlockReason=%5B%5BWikipedia%3AVandalism%7CVandalism%5D%5D", 'V+1 week', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=1+month&wpBlockReason=%5B%5BWikipedia%3AVandalism%7CVandalism%5D%5D", 'V+1 month', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=3+months&wpBlockReason=%5B%5BWikipedia%3AVandalism%7CVandalism%5D%5D", 'V+3 months', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=6+months&wpBlockReason=%5B%5BWikipedia%3AVandalism%7CVandalism%5D%5D", 'V+6 months', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=1+year&wpBlockReason=%5B%5BWikipedia%3AVandalism%7CVandalism%5D%5D", 'V+1 year', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=indefinite&wpBlockReason=%5B%5BWikipedia%3AVandalism%7CVandalism%5D%5D-only+account", 'Voa+indefinite', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=indefinite&wpBlockReason=sockpuppet", 'Sock+indefinite', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=indefinite&wpBlockReason=%7B%7Buw-ublock%7D%7D", 'Name+indefinite', '');
        addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/"+encodeURIComponent(lemma)+"&wpBlockOther=indefinite&wpBlockReason=%7B%7Buw-uhblock%7D%7D", 'Hardname+indefinite', '');
        if(Animum_testing == 1) addlilink(warnfunc, "http://en.wikipedia.org/w/index.php?title=Special:BlockIP/Animum's+Electric+Pajamas&wpBlockOther=24+hours&wpBlockReason=Test+block", 'Testblock+24 hours', '');
    }
  }
});