User:Animum/userrights.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.href = url; na.appendChild(document.createTextNode(name)); 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) {   var na = document.createElement('a'); na.href = '#'; var mn = document.createElement('ul'); na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); li.id = id; li.className = 'tabmenu'; li.appendChild(na); li.appendChild(mn); tabs.appendChild(li); return li; }

function addGroups(rollback, ipblockExempt, accountcreator, autoreviewer) { var accountcreator = accountcreator.length; var rollback = rollback.length; var ipblockExempt = ipblockExempt.length; var autoreviewer = autoreviewer.length;

if(rollback > 0) document.getElementById("wpGroup-rollbacker").checked = true; if(ipblockExempt > 0) document.getElementById("wpGroup-ipblock-exempt").checked = true; if(accountcreator > 0) document.getElementById("wpGroup-accountcreator").checked = true; if(autoreviewer > 0) document.getElementById("wpGroup-autoreviewer").checked = true;

document.getElementById("wpReason").value = "Granting the following right(s): " + (rollback > 0 ? "rollback" + (ipblockExempt > 0 || accountcreator > 0 || autoreviewer > 0 ? ", " : "") : "") + (ipblockExempt > 0 ? "ipblock-exempt" + (accountcreator > 0 || autoreviewer > 0 ? ", " : "") : "") + (accountcreator > 0 ? "accountcreator" + (autoreviewer > 0 ? ", " : "") : "") + (autoreviewer > 0 ? "autoreviewer" : ""); window.setTimeout(function { getElementsByClassName(document, "td", "mw-submit")[0].getElementsByTagName("input")[0].click; }, 2000); }

function removeGroups(rollback, ipblockExempt, accountcreator, autoreviewer) { var accountcreator = accountcreator.length; var rollback = rollback.length; var ipblockExempt = ipblockExempt.length; var autoreviewer = autoreviewer.length;

if(rollback > 0) document.getElementById("wpGroup-rollbacker").checked = false; if(ipblockExempt > 0) document.getElementById("wpGroup-ipblock-exempt").checked = false; if(accountcreator > 0) document.getElementById("wpGroup-accountcreator").checked = false; if(autoreviewer > 0) document.getElementById("wpGroup-autoreviewer").checked = false;

document.getElementById("wpReason").value = "Removing the following right(s): " + (rollback > 0 ? "rollback" + (ipblockExempt > 0 || accountcreator > 0 || autoreviewer > 0 ? ", " : "") : "") + (ipblockExempt > 0 ? "ipblock-exempt" + (accountcreator > 0 || autoreviewer > 0 ? ", " : "") : "") + (accountcreator > 0 ? "accountcreator" + (autoreviewer > 0 ? ", " : "") : "") + (autoreviewer > 0 ? "autoreviewer" : ""); window.setTimeout(function { getElementsByClassName(document, "td", "mw-submit")[0].getElementsByTagName("input")[0].click; }, 2000); }

$(function {   if(mw.config.get('wgCanonicalSpecialPageName') == "Userrights" && mw.config.get('wgNamespaceNumber') == -1 && document.getElementById("username").value.length > 0) {                addlimenu(document.getElementById("p-cactions").getElementsByTagName("ul")[0], "add", "ca-addrights", "");        var addrights = document.getElementById("ca-addrights").getElementsByTagName("ul")[0];        addlilink(addrights, "javascript:addGroups('rollback', , , )", "rollback", "");        addlilink(addrights, "javascript:addGroups(, 'ipblock-exempt', , )", "ipblock", "");        addlilink(addrights, "javascript:addGroups(, , 'accountcreator', )", "acc", "");        addlilink(addrights, "javascript:addGroups(, , , 'autoreviewer')", "autorev", "");        addlilink(addrights, "javascript:addGroups('rollback', 'ipblock-exempt', )", "rollback+ipblock", "");        addlilink(addrights, "javascript:addGroups('rollback', , 'accountcreator')", "rollback+acc", ""); addlilink(addrights, "javascript:addGroups('rollback', , , 'autoreviewer')", "rollback+autorev", ""); addlilink(addrights, "javascript:addGroups('', 'ipblock-exempt', 'accountcreator')", "ipblock+acc", ""); addlilink(addrights, "javascript:addGroups(, 'ipblock-exempt', , 'autoreviewer')", "rollback+autorev", ""); addlilink(addrights, "javascript:addGroups(, , 'accountcreator', 'autoreviewer')", "acc+autorev", ""); addlilink(addrights, "javascript:addGroups('rollback', 'ipblock-exempt', 'accountcreator', '')", "rollback+ipblock+acc", ""); addlilink(addrights, "javascript:addGroups('rollback', 'ipblock-exempt', '', 'autoreviewer')", "rollback+ipblock+autorev", ""); addlilink(addrights, "javascript:addGroups('', 'ipblock-exempt', 'accountcreator', 'autorev)", "ipblock+acc+autorev", ""); addlilink(addrights, "javascript:addGroups('rollback', 'ipblock-exempt', 'accountcreator', 'autoreviewer')", "rollback+acc+ipblock+autorev", "");

addlimenu(document.getElementById("p-cactions").getElementsByTagName("ul")[0], "remove", "ca-removerights", ""); var removerights = document.getElementById("ca-removerights").getElementsByTagName("ul")[0]; addlilink(removerights, "javascript:removeGroups('rollback', , , '')", "rollback", ""); addlilink(removerights, "javascript:removeGroups(, 'ipblock-exempt', , '')", "ipblock", ""); addlilink(removerights, "javascript:removeGroups(, , 'accountcreator', '')", "acc", ""); addlilink(removerights, "javascript:removeGroups(, , '', 'autoreviewer')", "autorev", ""); addlilink(removerights, "javascript:removeGroups('rollback', 'ipblock-exempt', '')", "rollback+ipblock", ""); addlilink(removerights, "javascript:removeGroups('rollback', '', 'accountcreator')", "rollback+acc", ""); addlilink(removerights, "javascript:removeGroups('rollback', , , 'autoreviewer')", "rollback+autorev", ""); addlilink(removerights, "javascript:removeGroups('', 'ipblock-exempt', 'accountcreator')", "ipblock+acc", ""); addlilink(removerights, "javascript:removeGroups(, 'ipblock-exempt', , 'autoreviewer')", "rollback+autorev", ""); addlilink(removerights, "javascript:removeGroups(, , 'accountcreator', 'autoreviewer')", "acc+autorev", ""); addlilink(removerights, "javascript:removeGroups('rollback', 'ipblock-exempt', 'accountcreator', '')", "rollback+ipblock+acc", ""); addlilink(removerights, "javascript:removeGroups('rollback', 'ipblock-exempt', '', 'autoreviewer')", "rollback+ipblock+autorev", ""); addlilink(removerights, "javascript:removeGroups('', 'ipblock-exempt', 'accountcreator', 'autorev)", "ipblock+acc+autorev", ""); addlilink(removerights, "javascript:removeGroups('rollback', 'ipblock-exempt', 'accountcreator', 'autoreviewer')", "rollback+acc+ipblock+autorev", ""); } });

$(function {   if(((mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3) && !mw.config.get('wgTitle').split("/")[1]) || (mw.config.get('wgNamespaceNumber') == -1 && mw.config.get('wgCanonicalSpecialPageName') == "Contributions")) {        mw.util.addPortletLink("p-cactions", mw.config.get('wgScript') + "?title=Special:UserRights&user=" + (mw.config.get('wgCanonicalSpecialPageName') == "Contributions" ? document.title.split("User contributions for ")[1].split(" - Wikipedia, the free encyclopedia")[0] : mw.config.get('wgTitle')), "userrights", "ca-userrights");    } });