User:AttemptToCallNil/common.js

// jshint jquery:true, esversion:6 /* globals require, module, mediaWiki, mw, OO */ 'use strict';

// 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 $(" ") .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"));	} });

// You should really not import my common.js. It is subject to change without notice, like what I did below /*$(function {	if (mw.config.get("wgUserName") !== "AttemptToCallNil") {		$("div#footer")			.append($(" ") .attr({					"id": "dontusemyjs",					"src": "https://minecraft.gamepedia.com/media/minecraft.gamepedia.com/8/84/Sheep3.ogg",					"autoplay": "autoplay",					"loop": "loop"				}) );		$("#dontusemyjs").trigger("play");	}	});*/

$(function {	var $rollback_outer = $(".mw-rollback-link");	var $rollback_old = $(".mw-rollback-link > a");	var $rollback_new = $rollback_old.clone;	$rollback_new.attr("href", null).insertAfter($rollback_old);	// should be moved to CSS, maybe will take effect immediately?	$rollback_old.css("display", "none");	$rollback_new.on( 'click', function { var $rollback = $( '#rollback-summary' ); if ( $( this ).parent.is( $rollback.parent ) ) { $rollback.toggle; console.log("same parent"); } else { console.log("different parents"); $rollback.remove; var name = decodeURIComponent( $rollback_old.prop( 'href' ).match( /&from=(.+)&token/ )[1].replace( /\+/g, ' ' ) ); $rollback = $( ' ' ).append(				$( ' ' ).addClass( 'mw-ui-input rollback-text' ).prop( { maxlength: 250, spellcheck: true } ).val( 'Revert consecutive edits by ' + name + ' (talk)' ),				$( ' ' ).addClass( 'mw-ui-button mw-ui-constructive rollback-submit-button' ).val( 'Rollback' )			).insertAfter( this ); }		// This puts the cursor at the end of the text var $text = $rollback.find( '.rollback-text' ); var summary = $text.val; $text.focus.val( '' ).val( summary ); } );	$( '#mw-content-text' ).on( 'click', '.rollback-submit-button', function { window.location = $rollback_old.prop( 'href' ) + '&summary=' + encodeURIComponent( $rollback_new.find( '.rollback-text' ).val ); } );	// Allow rollback to be submitted by pressing enter while focused on the input field	$( '#mw-content-text' ).on( 'keypress', '.rollback-text', function( e ) { if ( e.which !== 13 ) { return; }		e.preventDefault; $( '.rollback-submit-button' ).click; } );	// Close rollback if clicked anywhere else	$( window ).click( function( e ) { if ( !$( e.target ).is( '#rollback-summary' ) && !$( '#rollback-summary' ).has( e.target ).length ) { $( '#rollback-summary' ).hide; }	} ); } );