User:Aidan9382/scripts/show-all-isxyz-messages.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Aidan9382/scripts/show-all-isxyz-messages. |
//Shows all text normally hidden behind certain permissions
function showxyzProcessList(classname, displayname) {
var classSet = document.getElementsByClassName(classname);
for (var i=0; i<classSet.length; i++) {
var classElement = classSet[i];
var tag = classElement.tagName;
if (tag == "DIV" || tag == "P")
classElement.style = "display: block !important";
else if (tag == "SPAN" || tag == "SMALL")
classElement.style = "display: inline !important";
else if (tag == "LI")
classElement.style = "display: list-item !important";
else
classElement.style = "display: inline !important";
classElement.innerHTML = "<!--SHOWXYZ_S--><abbr class=\"isxyz-styling\" title=\"[ShowXYZ] This is "+displayname+" only text\"><!--SHOWXYZ_E-->"+classElement.innerHTML+"<!--SHOWXYZ_S--></abbr><!--SHOWXYZ_E-->";
}
return classSet.length;
}
function showxyzUnprocessList(classname, displayname) {
var classSet = document.getElementsByClassName(classname);
for (var i=0; i<classSet.length; i++) {
var classElement = classSet[i];
classElement.style = "";
classElement.innerHTML = classElement.innerHTML.replace(/<!--SHOWXYZ_S-->.*?<!--SHOWXYZ_E-->/, "").replace(/<!--SHOWXYZ_S-->.*?<!--SHOWXYZ_E-->/, ""); //Yes, twice
}
}
showxyzTags = {
"anonymous-show":"IP",
"user-show":"logged in",
"autoconfirmed-show":"autoconfirmed",
"unconfirmed-show":"unconfirmed",
"extendedconfirmed-show":"extendedconfirmed",
"nonextendedconfirmed-show":"non-extendedconfirmed",
"sysop-show":"administrator",
"checkuser-show":"checkuser",
"patroller-show":"NPP",
"abusefilter-show":"abusefilter",
"abusefilter-helper-show":"abusefilter helper",
"templateeditor-show":"template editor",
"extendedmover-show":"extendedmover"
};
function showxyzProcess() {
var changes = 0;
for (var tag in showxyzTags) { changes += showxyzProcessList(tag,showxyzTags[tag]); }
return changes;
}
function showxyzUnprocess() {
for (var tag in showxyzTags) { showxyzUnprocessList(tag,showxyzTags[tag]); }
}
var shownState = true; //Show by default
function showxyzToggleState() {
shownState = !shownState;
if (shownState) {
showxyzProcess();
} else {
showxyzUnprocess();
}
}
if (showxyzProcess() > 0) { //Only show portlet link if its even taken effect
mw.util.addCSS(".isxyz-styling {background: #ddd}");
mw.util.addPortletLink('p-tb', 'javascript:showxyzToggleState()', "Toggle ShowXYZ");
}