User:Awesome Aasim/DetectProtectionLevels.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. |
![]() | This user script seems to have a documentation page at User:Awesome Aasim/DetectProtectionLevels. |
/**
* All icons used in this script (linked here for attribution and for WhatLinksHere):
* [[File:Move-protection-shackle.svg]]
* [[File:Upload-protection-shackle.svg]]
* [[File:Semi-protection-unlocked.svg]]
* [[File:Full-protection-unlocked.svg]]
* [[File:Extended-protection-unlocked.svg]]
* [[File:Template-protection-unlocked.svg]]
* [[File:Semi-protection-shackle.svg]]
* [[File:Full-protection-shackle.svg]]
* [[File:Extended-protection-shackle.svg]]
* [[File:Template-protection-shackle.svg]]
* [[File:Generic-protected-shackle.svg]]
* [[File:Create-protection-unlocked.svg]]
* [[File:Create-protection-shackle.svg]]
* <nowiki>
**/
$(document).ready(function() {
var userGroups = mw.config.get("wgUserGroups");
var protImage = "";
var altProtImage1 = "";
var altProtImage2 = "";
var subsection = "";
// can move
try {
var moveProtectionLevels = mw.config.get("wgRestrictionMove");
var canMove = false;
if (moveProtectionLevels.length === 0) {
canMove = true;
} else {
for (var i = 0; i < userGroups.length; i++) {
if (userGroups[i] === moveProtectionLevels[0]) {
canMove = true;
}
}
}
if (canMove) {
//show the locks in their unlocked state
} else {
subsection = "move";
protImage = "/media/wikipedia/en/thumb/4/44/Move-protection-shackle.svg/20px-Move-protection-shackle.svg.png";
altProtImage1 = "/media/wikipedia/en/thumb/4/44/Move-protection-shackle.svg/30px-Move-protection-shackle.svg.png";
altProtImage2 = "/media/wikipedia/en/thumb/4/44/Move-protection-shackle.svg/40px-Move-protection-shackle.svg.png";
}
} catch (Error) {
console.error(Error);
}
// can upload
try {
var uploadProtectionLevels = mw.config.get("wgRestrictionUpload");
var canUpload = false;
if (uploadProtectionLevels.length === 0) {
canUpload = true;
} else {
for (i = 0; i < userGroups.length; i++) {
if (userGroups[i] === uploadProtectionLevels[0]) {
canUpload = true;
}
}
}
if (canUpload) {
//show the locks in their unlocked state
} else {
protImage = "/media/wikipedia/en/thumb/d/d7/Upload-protection-shackle.svg/20px-Upload-protection-shackle.svg.png";
altProtImage1 = "/media/wikipedia/en/thumb/d/d7/Upload-protection-shackle.svg/30px-Upload-protection-shackle.svg.png";
altProtImage2 = "/media/wikipedia/en/thumb/d/d7/Upload-protection-shackle.svg/40px-Upload-protection-shackle.svg.png";
subsection = "upload";
}
} catch (Error) {
console.error(Error);
}
// can edit
try {
var editProtectionLevels = mw.config.get("wgRestrictionEdit");
var canEdit = false;
if (editProtectionLevels.length === 0) {
canEdit = true;
} else {
for (i = 0; i < userGroups.length; i++) {
if (userGroups[i] === editProtectionLevels[0]) {
canEdit = true;
}
}
}
if (canEdit) {
//show the locks in their unlocked state
switch (editProtectionLevels[0]) {
case "autoconfirmed": protImage = "/media/wikipedia/commons/thumb/e/e0/Semi-protection-unlocked.svg/20px-Semi-protection-unlocked.svg.png";
altProtImage1 = "/media/wikipedia/commons/thumb/e/e0/Semi-protection-unlocked.svg/30px-Semi-protection-unlocked.svg.png";
altProtImage2 = "/media/wikipedia/commons/thumb/e/e0/Semi-protection-unlocked.svg/40px-Semi-protection-unlocked.svg.png";
subsection = "semi";
break;
case "sysop": protImage = "/media/wikipedia/commons/thumb/4/40/Full-protection-unlocked.svg/20px-Full-protection-unlocked.svg.png";
altProtImage1 = "/media/wikipedia/commons/thumb/4/40/Full-protection-unlocked.svg/30px-Full-protection-unlocked.svg.png";
altProtImage2 = "/media/wikipedia/commons/thumb/4/40/Full-protection-unlocked.svg/40px-Full-protection-unlocked.svg.png";
subsection = "full";
break;
case "extendedconfirmed": protImage = "/media/wikipedia/commons/thumb/d/db/Extended-protection-unlocked.svg/20px-Extended-protection-unlocked.svg.png";
altProtImage1 = "/media/wikipedia/commons/thumb/d/db/Extended-protection-unlocked.svg/30px-Extended-protection-unlocked.svg.png";
altProtImage2 = "/media/wikipedia/commons/thumb/d/db/Extended-protection-unlocked.svg/40px-Extended-protection-unlocked.svg.png";
subsection = "extended";
break;
case "templateeditor": protImage = "/media/wikipedia/en/thumb/5/5a/Template-protection-unlocked.svg/20px-Template-protection-unlocked.svg.png";
altProtImage1 = "/media/wikipedia/en/thumb/5/5a/Template-protection-unlocked.svg/30px-Template-protection-unlocked.svg.png";
altProtImage2 = "/media/wikipedia/en/thumb/5/5a/Template-protection-unlocked.svg/40px-Template-protection-unlocked.svg.png";
subsection = "template";
break;
}
} else {
switch (editProtectionLevels[0]) {
case "autoconfirmed": protImage = "/media/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/20px-Semi-protection-shackle.svg.png";
altProtImage1 = "/media/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/30px-Semi-protection-shackle.svg.png";
altProtImage2 = "/media/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/40px-Semi-protection-shackle.svg.png";
subsection = "semi";
break;
case "sysop": protImage = "/media/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/20px-Full-protection-shackle.svg.png";
altProtImage1 = "/media/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/30px-Full-protection-shackle.svg.png";
altProtImage2 = "/media/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/40px-Full-protection-shackle.svg.png";
subsection = "full";
break;
case "extendedconfirmed": protImage = "/media/wikipedia/en/thumb/8/8c/Extended-protection-shackle.svg/20px-Extended-protection-shackle.svg.png";
altProtImage1 = "/media/wikipedia/en/thumb/8/8c/Extended-protection-shackle.svg/30px-Extended-protection-shackle.svg.png";
altProtImage2 = "/media/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/40px-Full-protection-shackle.svg.png";
subsection = "extended";
break;
case "templateeditor": protImage = "/media/wikipedia/en/thumb/5/53/Template-protection-shackle.svg/20px-Template-protection-shackle.svg.png";
altProtImage1 = "/media/wikipedia/en/thumb/5/53/Template-protection-shackle.svg/30px-Template-protection-shackle.svg.png";
altProtImage2 = "/media/wikipedia/en/thumb/5/53/Template-protection-shackle.svg/40px-Template-protection-shackle.svg.png";
subsection = "template";
break;
default: protImage = "/media/wikipedia/en/thumb/9/99/Generic-protected-shackle.svg/20px-Generic-protected-shackle.svg.png";
altProtImage1 = "/media/wikipedia/en/thumb/9/99/Generic-protected-shackle.svg/30px-Generic-protected-shackle.svg.png";
altProtImage2 = "/media/wikipedia/en/thumb/9/99/Generic-protected-shackle.svg/40px-Generic-protected-shackle.svg.png";
break;
}
}
} catch (Error) {
console.error(Error);
}
// can create
try {
var createProtectionLevels = mw.config.get("wgRestrictionCreate");
var canCreate = false;
if (createProtectionLevels.length === 0) {
canCreate = true;
} else {
for (i = 0; i < userGroups.length; i++) {
if (userGroups[i] === createProtectionLevels[0]) {
canCreate = true;
}
}
}
if (canCreate) {
//show the locks unlocked
if (createProtectionLevels.length > 0) {
subsection = "create";
protImage = "/media/wikipedia/commons/thumb/8/86/Create-protection-unlocked.svg/20px-Create-protection-unlocked.svg.png";
altProtImage1 = "/media/wikipedia/commons/thumb/8/86/Create-protection-unlocked.svg/30px-Create-protection-unlocked.svg.png";
altProtImage2 = "/media/wikipedia/commons/thumb/8/86/Create-protection-unlocked.svg/40px-Create-protection-unlocked.svg.png";
}
} else {
subsection = "create";
protImage = "/media/wikipedia/en/thumb/0/02/Create-protection-shackle.svg/20px-Create-protection-shackle.svg.png";
altProtImage1 = "/media/wikipedia/en/thumb/0/02/Create-protection-shackle.svg/30px-Create-protection-shackle.svg.png";
altProtImage2 = "/media/wikipedia/en/thumb/0/02/Create-protection-shackle.svg/40px-Create-protection-shackle.svg.png";
}
} catch (Error) {
console.error(Error);
}
if (protImage.length > 0) {
if ($("#mw-indicator-pp-default").length > 0) $("#mw-indicator-pp-default").html("<span><a title=\"This page is protected.\" href=\"/wiki/Wikipedia:Protection_policy#" + subsection + "\"><img height=\"20\" src=\"" + protImage + "\" srcset=\"" + altProtImage1 + " 1.5x, " + altProtImage2 + " 2x\" alt=\"Protected page lock\"></a></span>");
else $(".mw-indicators").append("<div class=\"mw-indicator\" id=\"mw-indicator-pp-default\"><span><a title=\"This page is protected.\" href=\"/wiki/Wikipedia:Protection_policy#" + subsection + "\"><img height=\"20\" src=\"" + protImage + "\" srcset=\"" + altProtImage1 + " 1.5x, " + altProtImage2 + " 2x\" alt=\"Protected page lock\"></a></span></div>");
}
});
//</nowiki>