Documentation may be created at User:Leduyquang753/ProtectionIndicator.js/doc.
Note: After saving, you have to bypass your browser's cache to see the changes.
Google Chrome, Firefox, Microsoft Edge, and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button.
For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Page protection indicators
function getImageThumbnailURL(name, store, size) {
var encodedName = encodeURIComponent(name.replace(/ /g, "_"));
return "https://minecraft.gamepedia.com/media/minecraft.gamepedia.com/thumb/"
+ store
+ "/"
+ encodedName
+ "/"
+ size
+ "px-"
+ encodedName;
}
function mimicIndicator(id, link, imgName, imgStore, title) {
var encodedLink = encodeURIComponent(link.replace(/ /g, "_"));
return $("<div></div>")
.attr("id", "mw-indicator-" + id)
.addClass("mw-indicator")
.append($("<a></a>")
.attr({
"href": "/" + encodedLink,
"title": title
}).append($("<img>")
.attr({
"alt": title,
"src": getImageThumbnailURL(imgName, imgStore, 26),
"width": "25",
"height": "25"
})
)
);
}
$(function() {
var protectionLevelData = mw.config.get("wgRestrictionEdit");
if (protectionLevelData === null) {
// Null on nonexistent or special pages. Avoids a crash there.
return;
}
if (mw.config.get("wgAction") !== "view") {
// No need to display the indicator when viewing history or editing the page
return;
}
if (mw.config.get("wgPageName") === "Minecraft_Wiki") {
// The indicator lock breaks formatting on the main page due to the level 1 header being hidden
return;
}
var protectionLevel = protectionLevelData[0];
if (protectionLevel === "autoconfirmed") {
mimicIndicator(
"protection-semi",
"Minecraft Wiki:Autoconfirmed users",
"Semi Protected Pixelart Lock.png",
"5/54",
"Semi-protected"
).appendTo($(".mw-indicators"));
} else if (protectionLevel === "directoreditprotected") {
mimicIndicator(
"protection-director",
"Minecraft Wiki:Directors",
"Office Protected Pixelart Lock.png",
"3/38",
"Director protected"
).appendTo($(".mw-indicators"));
} else if (protectionLevel === "sysop") {
mimicIndicator(
"protection-full",
"Minecraft Wiki:Administrators",
"Fully Protected Pixelart Lock.png",
"7/70",
"Fully protected"
).appendTo($(".mw-indicators"));
}
});