User:Manishearth/ACC.js

/*  */ //Blacklisted strings: var blacklistRegEx = new RegExp("(wikimedia|wikipedia|admin|steward|bureaucrat|sysop|crat|checkuser|oversight|moderator|bot)","gi") //Color of blacklisted usernames var blacklistColor="red"; //Color of blacklisted usernames var handleBrown="hidden"; //Action to take against brown links ("hidden" or "visible") var handleBlue="hidden" //Action to take against green links ("hidden" or "visible") var remainingBrown=new RegExp("(UPolicy|Custom|Drop|Users|Checkusers)","gi") //Which brown links to leave untouched

var blacklistNotice =" [This username is blacklisted. Click here to restore hidden actions] "; //Blacklist notice. Please keep it wrapped in a /* */ /* The main method. This method searches for usernames which contain blacklisted strings, marks the username red, and hides the action buttons ("Created!","Similar","Taken","SUL Taken", etc.), except Upolicy, Custom, Drop. It also hides the blue "Create!" link. A notice is also shown, saying: "[Some actions have been hidden from view for blacklisted usernames (in red). Click here to restore]", alongwith a link to restore the hidden stuff (In case the account creator decides that the username is not a violation) function catchBlacklist{ caughtBL=true; var reqs=getElementsByClass("request-req") //Gets the list of usernames (Not exactly, actually it gets all of the blue links, but it can't interfere) var restoreLinkNeed=false if(reqs[0].innerHTML.toLowerCase.search(blacklistRegEx)!=-1){ restoreLinkNeed=true //flag reqs[0].style.color=blacklistColor; //Make it red reqs[0].style.fontWeight="bold"; reqs[0].style.fontStyle="italic"; var rLine= reqs[0].parentNode.parentNode.parentNode; //The full entry, we were before referring to just the element containing the username var rActions=getElementsByClass("request-done") //Gets the action list (brown links) from the above entry for(var j=0;j<rActions.length;j++){ if(rActions[j].innerHTML.search(remainingBrown)==-1){ rActions[j].style.visibility=handleBrown //(Hides all actions (brown links) except Upolicy, Custom, Drop) }			}			var rquestReq=getElementsByClass("request-req-create") // The blue links rquestReq[0].style.visibility=handleBlue; //hide Just the "Create!" blue link }	if(restoreLinkNeed&&document.location.toString.indexOf("zoom")!=-1){ document.getElementById("content").childNodes[0].innerHTML+=" "+blacklistNotice+" "; } } /* This method undos all of the actions that catchBlacklist does, except that it leaves the blacklisted usernames red. function restore{ //Pretty much a copy of the second part of catchBlacklist, except that it makes hidden stuff visible var reqs=getElementsByClass("request-req")

if(reqs[0].innerHTML.toLowerCase.search(blacklistRegEx)!=-1){ var rLine= reqs[0].parentNode.parentNode.parentNode; var rActions=getElementsByClass("request-done") for(var j=0;j<rActions.length;j++){ rActions[j].style.visibility="visible" //Make it visible }			var rquestReq=getElementsByClass("request-req-create") rquestReq[0].style.visibility="visible"; //make it visible }	document.getElementById('restoreLink').style.display='none' //Hide the notice, the user has read it } var restoreLinkAdded=false; //A flag to check if the "Restore actions" link has been added /* Shortcut method for convenience--returns an array of elements in one class */ function getElementsByClass(searchClass,node) { var classElements = new Array; if ( node == null ) node = document; tag="*"; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)'); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; }	}	return classElements; } //Runs the main method on certain pages only if(document.location.toString.indexOf("zoom")!=-1){ var blkListLoadedTimer= setInterval(blkListStart,1000); } function blkListStart{ if(document.readyState=="complete"){ clearInterval(blkListLoadedTimer); }else{ return; }	if(document.getElementById("content")){ if(document.getElementById("content").childNodes[0]){ var heading=document.getElementById("content").childNodes[0].innerHTML; if(heading.indexOf("Details for Request #")!=-1){ catchBlacklist }	} } }