Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
//<pre><nowiki>
/**********************************
 *  EasyBlock v2.0                *
 **********************************
 *  By Animum                     *
 *****************************************************************************
 *  To install, add the following to your monobook.js file:                  *
 *                                                                           *
    importScript('User:Animum/easyblock.js'); //[[User:Animum/easyblock.js]]
 *****************************************************************************/
 
/*******************************
 *  Handy-dandy block script   *
 *******************************
 *  Code authored more or less *
 *  by me, but still has some  *
 *  snippets by DerHexer or    *
 *  Voice of All.              *
 *******************************
 *  This script has only been  *
 *  tested in Firefox. It may  *
 *  not work in other          *
 *  browsers.                  *
 *******************************/
 
/* Libraries that support this script */

var UrlParameters = new Array ();
 
 function readparams() {
  var asReadInUrlParameters;
  var asReadInUrlParameter;
 
  // Get URL parameters
  asReadInUrlParameters = location.search.substring(1, location.search.length).split("&");
  for (i = 0; i < asReadInUrlParameters.length; i++) {
    asReadInUrlParameter = asReadInUrlParameters[i].split("=");
    UrlParameters[decodeURIComponent(asReadInUrlParameter[0])] = decodeURIComponent(asReadInUrlParameter[1]);
  }
 }

 readparams();

importStylesheet('User:Animum/addlimenu.css');
 
function easyblock() {}
 
easyblock.addlilink = function(tabs, href, name, id, title, key){
    var na = document.createElement('a');
    na.href = href;
    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;
}
 
easyblock.addlimenu = function(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
}
 
easyblock.zeroPad = function(str) {
 return ("0" + str).slice(-2);
}
 
easyblock.formatResponse = function(response) { //This bit was stolen from Gracenotes.  Thanks, Gracenotes!
    try {
        response = response.query.pages;
        for (var property in response)
            return response[property];
    } catch (e) {
        return response.query.pages["-1"];
    }
}
 
easyblock.textUpdate = function(message, br) {
    if(typeof(br) == 'undefined') br = true;
    document.getElementById("contentSub").innerHTML += (br ? "<br />" : "") + "<b>" + message + "</b>";
}
 
easyblock.bgColor = function(color) {
    document.getElementById("content").style.backgroundColor = color;
}
 
easyblock.isSensitive = function(address) { //Stolen from [[MediaWiki:Sysop.js]].
    ips = Array(
        Array(/\b63\.162\.143\.21\b/),
        Array(/\b82\.148\.9(6\.68|7\.69)\b/),
        Array(/\b128\.183\.103\.97\b/),
        Array(/\b(((2|5)?6|7|[12]1|2(2|8|9)|3(0|3)|55)\.([01]?\d\d?|2(5[0-5]|[0-4]\d))|130\.22)(\.([01]?\d\d?|2(5[0-5]|[0-4]\d))){2}\b/),
        Array(/\b138\.16[23](\.([01]?\d\d?|2(5[0-5]|[0-4]\d))){2}\b/),
        Array(/\b143\.2(2[89]|3[01])(\.([01]?\d\d?|2(5[0-5]|[0-4]\d))){2}\b/),
        Array(/\b149\.101(\.([01]?\d\d?|2(5[0-5]|[0-4]\d))){2}\b/),
        Array(/\b156\.33(\.([01]?\d\d?|2(5[0-5]|[0-4]\d))){2}\b/),
        Array(/\b(162\.4[56]\.([01]?\d\d?|2(5[0-5]|[0-4]\d))|198\.81\.(128|129|1[3-8]\d|191))\.([01]?\d\d?|2(5[0-5]|[0-4]\d))\b/),
        Array(/\b192\.197\.(7[7-9]|8[0-6])\.([01]?\d\d?|2(5[0-5]|[0-4]\d))\b/),
        Array(/\b(51(\.([01]?\d\d?|2(5[0-5]|[0-4]\d))){2}|194.60.\d[0-5]?)\.([01]?\d\d?|2(5[0-5]|[0-4]\d))\b/),
        Array(/\b66\.230\.(19[2-9]|2[0-3]\d)\.([01]?\d\d?|2(5[0-5]|[0-4]\d))\b/),
        Array(/\b91\.198\.174\.(19[2-9]|2([01]\d|2[0-3]))\b/)
    );
    ip = address;
    if (/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/.test(ip)) {
        for (i = 0; i < ips.length; i++) {
            if (ip.match(ips[i][0])) {
                return true;
            } else {
                return false;
            }
        }
    }
}
/* End of library section */
 
//I authored (most of) what is below.
//-----------------------------------
//Preferences
if(typeof(ebPrefs) == 'undefined') {
    ebPrefs = {};
}
 
if(typeof(ebPrefs.markWarnAsMinor) == 'undefined') {
    ebPrefs.markWarnAsMinor = 1;
}
 
if(typeof(ebPrefs.watchlistWarn) == 'undefined' ) {
    ebPrefs.watchlistWarn = 0;
}
 
if(typeof(ebPrefs.showOnPages) == 'undefined') {
    ebPrefs.showOnPages = ["user_usertalk", "contribs", "diffs", "ipblocklist", "blockip"];
}
 
if(typeof(ebPrefs.useAutoWarn) == 'undefined') {
    ebPrefs.useAutoWarn = true;
}
 
if(typeof(ebPrefs.loadCommentOnSubmit) == 'undefined') {
    ebPrefs.loadCommentOnSubmit = true;
}
//End of Preferences section.
 
easyblock.canShowOn = function(pgName) { //For reading the ebPrefs.showOnPages data.
    for(var index in ebPrefs.showOnPages) { 
        if(ebPrefs.showOnPages[index].indexOf(pgName) != -1) { 
            return true;
        } else {
            if(index < 4) { //We only have 5 options!
                index++; 
            } else { 
                return false; 
            }
        }
    }
}
 
easyblock.isBlocked = function(name) {
    var req = sajax_init_object();
    req.open("GET", "/w/api.php?action=query&list=blocks&bkusers=" + name + "&format=json", false);
    req.send(null);
    var info = eval("(" + req.responseText + ")");
    return (info.query.blocks[0] ? true : false);
}
 
easyblock.userBlocked = function(name) {
    var req = sajax_init_object();
    req.open("GET", "/w/api.php?action=query&list=blocks&bkusers=" + name + "&format=json&bkprop=by", false);
    req.send(null);
    var info = eval("(" + req.responseText + ")");
    if(info.query.blocks[0]) {
        return (escape(info.query.blocks[0].by) == wgUserName ? true : false);
    } else {
        return false;
    }
}
 
easyblock.warn = function(page, comment, summary, replacePage, loadCommentOnSubmit) {
    if(typeof(loadCommentOnSubmit) == 'undefined') loadCommentOnSubmit = true;
    page = decodeURIComponent(page);
    var req = sajax_init_object();
    req.open("GET", "/w/api.php?action=query&prop=info|revisions&format=json&intoken=edit&rvprop=content|timestamp&titles=" + encodeURIComponent(page), false);
    this.textUpdate("Adding \"" + comment + "\" to <a href=\"/wiki/" + encodeURIComponent(page) + "\">" + page + "</a>...");
    req.send(null);
 
    var info = this.formatResponse(eval("(" + req.responseText + ")"));
    var date = new Date();
    var startTime = date.getUTCFullYear() + this.zeroPad(date.getUTCMonth() + 1) + this.zeroPad(date.getUTCDate()) + this.zeroPad(date.getUTCHours()) + this.zeroPad(date.getUTCMinutes()) + this.zeroPad(date.getUTCSeconds());
    var editTime = (info.revisions ? info.revisions[0].timestamp.replace(/[^0-9]/g, "") : startTime); 
    var content = (info.revisions ? (info.revisions[0]["*"].length > 0 ? info.revisions[0]["*"] : "") : "");
    var editToken = info.edittoken;
 
    var postdata = 'wpTextbox1=' + (replacePage == true ? encodeURIComponent(comment) : encodeURIComponent(content + (content.length > 0 ? "\n\n" : "") + comment))
                 + '&wpSummary=' + encodeURIComponent(summary)
                 + '&wpSave=save'
                 + '&wpEditToken=' + encodeURIComponent(editToken)
                 + '&wpEdittime=' + editTime
                 + '&wpStarttime=' + startTime
                 + '&wpMinoredit=' + ebPrefs.markWarnAsMinor
                 + '&wpWatchthis=' + ebPrefs.watchlistWarn;
 
    var req = sajax_init_object();
    req.open("POST", "/w/index.php?title=" + encodeURIComponent(page) + "&action=submit", false);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.setRequestHeader("Content-Length", postdata.length);
    req.send(postdata)
        if(req.readyState == 4) this.textUpdate(" done!", false);
    if(loadCommentOnSubmit && ebPrefs.loadCommentOnSubmit) {
        this.textUpdate(page.split(":")[1] + " has been blocked and warned. Redirecting to " + page + "...");
        this.bgColor("#EEF"); //We're done.
        window.setTimeout(function() { location.href = "/wiki/" + encodeURIComponent(page); }, 2000);
    }
}
 
easyblock.warnAndTag = function(page, comment, summary, replacePage, page2, comment2, summary2, replacePage2) {
    this.warn(page, comment, summary, replacePage, false);
    this.warn(page2, comment2, summary2, replacePage2);
}
 
easyblock.block = function(name, reason, duration) {
    //Safeguards against errors
    document.getElementById("contentSub").innerHTML += "<br />";
    if(this.isBlocked(name)) {
        this.textUpdate("Error:  " + name + " is already blocked. (<a href=\"http://en.wikipedia.org/w/index.php?title=Special:IPBlockList&action=unblock&ip=" + name + "\">unblock</a>)");
        return;
    } 
    if(this.isSensitive(name)) {
        this.textUpdate("Aborting:  " + name + " is marked as a sensitive address.");
        return;
    }
    if(name == "undefined") { 
        this.textUpdate("Error:  No valid username was given; please block manually.  If this problem persists across many pages, <a href=\"http://en.wikipedia.org/w/index.php?title=User_talk:Animum&action=edit&section=new\">contact Animum</a>.");
        return;
    }
 
    //If none of these safeguards have been triggered, continue.
    var req = sajax_init_object();
    req.open("GET", "/w/api.php?action=query&prop=info&intoken=block&titles=User:" + name + "&format=json", false);
    req.send(null);
    this.bgColor("#EFE"); //Begin.
 
    var info = this.formatResponse(eval("(" + req.responseText + ")"));
    var edittoken = info.blocktoken;
    var warnurl;
    var emailBan;
    var enableAutoblock;
    var createAccount;
    if(reason == "sockpuppet") {
        sockof = prompt("Of whom is this user a sockpuppet?");
        if(!sockof) return;
        reason = "\[\[w:Wikipedia:Sock puppetry\|Sock puppet\]\] of \[\[User:" + sockof + "\|" + sockof + "\]\]";
    }
    if(duration == "indefinite") { //0 means false; 1 means true.
        if(reason != "{{uw-ublock}}") {
            emailBan = 0;
            createAccount = 1;
            enableAutoblock = 1;
        } else {
            createAccount = 0;
            enableAutoblock = 0;
            emailBan = 0;
        }
    } else { 
        emailBan = 0;
        createAccount = 1;
        enableAutoblock = 1;
    }
    var postdata = "wpBlockAddress=" + encodeURIComponent(name)
                 + "&wpBlockOther=" + encodeURIComponent(duration)
                 + "&wpBlockReason=" + encodeURIComponent(reason)
                 + "&wpBlockReasonList=other"
                 + "&wpEmailBan=" + emailBan
                 + "&wpCreateAccount=" + createAccount
                 + "&wpEnableAutoblock=" + enableAutoblock
                 + "&wpEditToken=" + encodeURIComponent(edittoken)
                 + "&wpBlock=block";
    var req = sajax_init_object();
    req.open("POST", "/w/index.php?title=Special:BlockIP&action=submit", false);
    req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    req.setRequestHeader('Content-length', postdata.length);
    req.send(postdata);
    if(this.userBlocked(name)) { //Make sure we really are done.
        if(ebPrefs.useAutoWarn == true) {
            if(reason.indexOf("Sock puppetry") != -1) {
                this.warnAndTag("User talk:" + name, "\{\{subst\:User:Animum/sockblock\|" + sockof + "\}\} \~\~\~\~", "You are a sockpuppet or are suspected to be a sockpuppet of \[\[User\:" + sockof + "\|" + sockof + "\]\] and have been blocked indefinitely.", false, "User:" + name, "\{\{subst:User:Animum/sockpuppet\|" + sockof + "\|blocked\}\}", "You are a sockpuppet or are suspected to be a sockpuppet of \[\[User\:" + sockof + "\|" + sockof + "\]\] and have been blocked indefinitely.", true);
            }
            if(reason == "[[Wikipedia:Vandalism|Vandalism]]") {
                this.warn("User talk:" + name, "\{\{subst\:User:Animum/vblock\|time=" + duration + "\|subst\=subst\:\|sig\=y\}\}", "Due to recent \[\[Commons\:Vandalism\|vandalism\]\] from this " + (name.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 " + duration + ".", false);
            }
            if(reason == "{{uw-uhblock}}" || reason == "{{uw-ublock}}") {
                this.warn("User talk:" + name, "\{\{subst:Username block\|sig\=y\|subst\=subst\:\}\}", "Your username is needlessly offensive, attacks or impersonates another person, or clearly suggests that your intention is not to contribute to the Commons in a constructive manner.", false);
            }
            if(reason == "[[Wikipedia:Vandalism|Vandalism]]-only account") {
                this.warn("User talk:" + name, "\{\{subst\:User:Animum/voablock\|subst\=subst\:\|sig\=y\}\}", "You have been blocked indefinitely because your account has been used only for \[\[Commons\:Vandalism\|vandalism\]\].", false);
            }
        } else {
            this.bgColor("#EEF");
        }
    } else { //Change bgColor when we have nothing else to do.
        this.textUpdate("An unknown error has occurred.  Please block manually.");
        this.bgColor("#EEF"); //We're done.
    }
}
 
easyblock.getLastBlock = function(user) {
    var req = sajax_init_object();
    req.open("GET", "/w/api.php?format=json&action=query&list=logevents&letype=block&letitle=User:" + user + "&leprop=details", false);
    req.send(null);
    var response = eval("(" + req.responseText + ")");
    if(response.query.logevents[0]) {
        return (this.isBlocked(user) ? "blocked" : "last block") + ": " + response.query.logevents[0].block.duration;
    } else {
        return "not blocked before";
    }
}
 
easyblock.showTab = 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"] > "") {
        lemma = document.evaluate('//div[@id="mw-diff-ntitle2"]//a[3]/@title', document, null, XPathResult.STRING_TYPE, null).stringValue.split("/")[1];
    }
 
    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") {
        var lemma = decodeURIComponent(document.evaluate('//div[@id="contentSub"]/a[1]/@href', document, null, XPathResult.STRING_TYPE, null).stringValue.split(":")[1].split("&")[0]).replace(/[+_]/g, " ");
    }
 
    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(((wgNamespaceNumber == 2 || wgNamespaceNumber == 3) && this.canShowOn("user_usertalk")) || (UrlParameters["diff"] > "" && this.canShowOn("diffs")) || (wgPageName == "Special:Contributions" && this.canShowOn("contribs")) || (wgPageName == "Special:BlockIP" && this.canShowOn("blockip")) || (window.location.href.indexOf("Special:IPBlockList&action=success&successip=") != -1 && this.canShowOn("ipblocklist"))) {
        if((wgPageName == "Special:BlockIP" && window.location.href.indexOf("&action=success") != -1) || (wgPageName == "Special:BlockIP" && document.forms["blockip"].elements["wpBlockAddress"].value.length == 0)) {
            return;
        } else {
            this.addlimenu(document.getElementById('p-cactions').getElementsByTagName('ul')[0], 'block', 'warnfunc', '');
            var warnfunc = document.getElementById('warnfunc').getElementsByTagName('ul')[0];
            this.addlilink(warnfunc, "#", this.getLastBlock(decodeURIComponent(lemma)), "");
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\[\[Commons:Vandalism|Vandalism\]\]\", \"24 hours\")", 'V+24 hours', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\[\[Commons:Vandalism|Vandalism\]\]\", \"31 hours\")", 'V+31 hours', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\[\[Commons:Vandalism|Vandalism\]\]\", \"3 days\")", 'V+3 days', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\[\[Commons:Vandalism|Vandalism\]\]\", \"1 week\")", 'V+1 week', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\[\[Commons:Vandalism|Vandalism\]\]\", \"1 month\")", 'V+1 month', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\[\[Commons:Vandalism|Vandalism\]\]\", \"3 months\")", 'V+3 months', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\[\[Commons:Vandalism|Vandalism\]\]\", \"6 month\")", 'V+6 months', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\[\[Commons:Vandalism|Vandalism\]\]\", \"1 year\")", 'V+1 year', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\[\[Commons:Vandalism|Vandalism\]\]\-only account\", \"indefinite\")", 'Voa+indefinite', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"sockpuppet\", \"indefinite\")", 'Sock+indefinite', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\{\{Username blocked\}\}\", \"indefinite\")", 'Name+indefinite', '');
            this.addlilink(warnfunc, "javascript:easyblock.block(\"" + decodeURIComponent(lemma).replace(/_/g, " ") + "\", \"\{\{Username blocked\}\}\", \"indefinite\")", 'Hardname+indefinite', '');
        }
    }
}
 
function ebShowTab() { //Hacking
    easyblock.showTab();
}

$(ebShowTab);