User:Madminecrafter12/common.js

// Initialises stripes on all zebra tables after page load $(document).ready(function {	$('table.zebra tbody tr:nth-child(even)').addClass('even');	$('table.zebra tbody tr:nth-child(odd)').addClass('odd'); });

// Re do stripes on a table after sort finishes $(document).on('sortEnd.tablesorter', function(event) {	var table = $(event.target);	if(table.hasClass('zebra')) {		$('tbody tr:nth-child(even)',table).addClass('even').removeClass('odd');		$('tbody tr:nth-child(odd)',table).addClass('odd').removeClass('even');	} });

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 $(" ") .attr("id", "mw-indicator-" + id) .addClass("mw-indicator") .append($("")			.attr({ "href": "/" + encodedLink, "title": title }).append($(" ") .attr({				"alt": title,				"src": getImageThumbnailURL(imgName, imgStore, 25),				"srcset": getImageThumbnailURL(imgName, imgStore, 38)					+ " 1.5x, "					+ getImageThumbnailURL(imgName, imgStore, 50)					+ " 2x",				"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 page lock.png", "9/9b", "This page is semi-protected so that only registered users can edit it." ).appendTo($(".mw-indicators"));	} else if (protectionLevel === "directoreditprotected") {		mimicIndicator( "protection-director", "Minecraft Wiki:Directors", "Director-protected page lock.png", "8/85",			"This page is directors-only protected so that only directors can edit it." ).appendTo($(".mw-indicators"));	} else if (protectionLevel === "sysop") {		mimicIndicator( "protection-full", "Minecraft Wiki:Administrators", "Fully-protected page lock.png", "4/49",			"This page is fully protected so that only administrators can edit it." ).appendTo($(".mw-indicators"));	} });

// A toggle script for hiding "patrol-requests". // This is basically just a function for hiding a heading with underlying conversation. // // Created by User:Jack McKalling

// append script to document $(document).ready(function {	// create handler for displaying hideable patrol requests   $(".patrol-request-toggle-show").on("click", function { $(".patrol-request-hide").next("dl").show; $(".patrol-request-hide").show; // unhide "empty" page headings $("h2").nextAll("h3").each(function {   		var headingContent = $(this).nextUntil("h3");            if (headingContent.length > 0 // if heading has content at all && headingContent.is(function { return $(this).is(".patrol-request-hide"); }) // and contains finished requests && !headingContent.is(function { return $(this).is(".patrol-request"); })) { // but no unfinished ones             $(this).show;            }    	}); });   // create handler for hiding hideable patrol requests    $(".patrol-request-toggle-hide").on("click", function { $(".patrol-request-hide").next("dl").hide; $(".patrol-request-hide").hide; // hide "empty" page headings $("h2").nextAll("h3").each(function {   		var headingContent = $(this).nextUntil("h3");            if (headingContent.length > 0 // if heading has content at all && headingContent.is(function { return $(this).is(".patrol-request-hide"); }) // and contains finished requests && !headingContent.is(function { return $(this).is(".patrol-request"); })) { // but no unfinished ones             $(this).hide;            }    	}); }); });