User:Awesome Aasim/DetectProtectionLevels.js

/** * All icons used in this script (linked here for attribution and for WhatLinksHere): * *  *  *  *  *  *  *  *  *  *  *  *  *  **/ $(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 = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Move-protection-shackle.svg/20px-Move-protection-shackle.svg.png";			altProtImage1 = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Move-protection-shackle.svg/30px-Move-protection-shackle.svg.png";			altProtImage2 = "//upload.wikimedia.org/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 = "//upload.wikimedia.org/wikipedia/en/thumb/d/d7/Upload-protection-shackle.svg/20px-Upload-protection-shackle.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/en/thumb/d/d7/Upload-protection-shackle.svg/30px-Upload-protection-shackle.svg.png"; altProtImage2 = "//upload.wikimedia.org/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 = "//upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Semi-protection-unlocked.svg/20px-Semi-protection-unlocked.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Semi-protection-unlocked.svg/30px-Semi-protection-unlocked.svg.png"; altProtImage2 = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Semi-protection-unlocked.svg/40px-Semi-protection-unlocked.svg.png"; subsection = "semi"; break; case "sysop": protImage = "//upload.wikimedia.org/wikipedia/commons/thumb/4/40/Full-protection-unlocked.svg/20px-Full-protection-unlocked.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/commons/thumb/4/40/Full-protection-unlocked.svg/30px-Full-protection-unlocked.svg.png"; altProtImage2 = "//upload.wikimedia.org/wikipedia/commons/thumb/4/40/Full-protection-unlocked.svg/40px-Full-protection-unlocked.svg.png"; subsection = "full"; break; case "extendedconfirmed": protImage = "//upload.wikimedia.org/wikipedia/commons/thumb/d/db/Extended-protection-unlocked.svg/20px-Extended-protection-unlocked.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/commons/thumb/d/db/Extended-protection-unlocked.svg/30px-Extended-protection-unlocked.svg.png"; altProtImage2 = "//upload.wikimedia.org/wikipedia/commons/thumb/d/db/Extended-protection-unlocked.svg/40px-Extended-protection-unlocked.svg.png"; subsection = "extended"; break; case "templateeditor": protImage = "//upload.wikimedia.org/wikipedia/en/thumb/5/5a/Template-protection-unlocked.svg/20px-Template-protection-unlocked.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/en/thumb/5/5a/Template-protection-unlocked.svg/30px-Template-protection-unlocked.svg.png"; altProtImage2 = "//upload.wikimedia.org/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 = "//upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/20px-Semi-protection-shackle.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/30px-Semi-protection-shackle.svg.png"; altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/40px-Semi-protection-shackle.svg.png"; subsection = "semi"; break; case "sysop": protImage = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/20px-Full-protection-shackle.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/30px-Full-protection-shackle.svg.png"; altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/40px-Full-protection-shackle.svg.png"; subsection = "full"; break; case "extendedconfirmed": protImage = "//upload.wikimedia.org/wikipedia/en/thumb/8/8c/Extended-protection-shackle.svg/20px-Extended-protection-shackle.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/en/thumb/8/8c/Extended-protection-shackle.svg/30px-Extended-protection-shackle.svg.png"; altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/40px-Full-protection-shackle.svg.png"; subsection = "extended"; break; case "templateeditor": protImage = "//upload.wikimedia.org/wikipedia/en/thumb/5/53/Template-protection-shackle.svg/20px-Template-protection-shackle.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/en/thumb/5/53/Template-protection-shackle.svg/30px-Template-protection-shackle.svg.png"; altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/5/53/Template-protection-shackle.svg/40px-Template-protection-shackle.svg.png"; subsection = "template"; break; default: protImage = "//upload.wikimedia.org/wikipedia/en/thumb/9/99/Generic-protected-shackle.svg/20px-Generic-protected-shackle.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/en/thumb/9/99/Generic-protected-shackle.svg/30px-Generic-protected-shackle.svg.png"; altProtImage2 = "//upload.wikimedia.org/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 = "//upload.wikimedia.org/wikipedia/commons/thumb/8/86/Create-protection-unlocked.svg/20px-Create-protection-unlocked.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/commons/thumb/8/86/Create-protection-unlocked.svg/30px-Create-protection-unlocked.svg.png"; altProtImage2 = "//upload.wikimedia.org/wikipedia/commons/thumb/8/86/Create-protection-unlocked.svg/40px-Create-protection-unlocked.svg.png"; }        } else { subsection = "create"; protImage = "//upload.wikimedia.org/wikipedia/en/thumb/0/02/Create-protection-shackle.svg/20px-Create-protection-shackle.svg.png"; altProtImage1 = "//upload.wikimedia.org/wikipedia/en/thumb/0/02/Create-protection-shackle.svg/30px-Create-protection-shackle.svg.png"; altProtImage2 = "//upload.wikimedia.org/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("  "); else $(".mw-indicators").append("  "); } }); //