MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. See MediaWiki:Wikia.js for scripts that only affect the oasis skin. /* Table of Contents --- * (B00) Element animator * (W00) Small scripts * (X00) importArticle pre-script actions * * (X01) Less * * (X02) UserTagsJS * * (X03) HighlightUsers * (Y00) importArticles

/* jshint esversion: 5, forin: true, immed: true, indent: 4, latedef: true, newcap: true, noarg: true, undef: true, undef: true, unused: true, browser: true, jquery: true, onevar: true, eqeqeq: true, multistr: true, maxerr: 999999, -W082, -W084 /* global mw, importScripts */

// Small script to change wall text $('a[title="Message Wall"]').html('wall'); $('a.external.text').removeAttr('target');

// Add custom "focusable" class $('.focusable').attr('tabindex', 0);

// Add comment guidelines notice (wiki/fandom staff/users with > 100 edits exempt) if (!/bureaucrat|content-moderator|threadmoderator|rollback|sysop|util|staff|helper|global-discussions-moderator|wiki-manager|soap/.test(mw.config.get('wgUserGroups').join('\n')) && mw.config.get('wgEditCount') < 100) { mw.loader.using([ 'mediawiki.api' ]).then(function {		var api = new mw.Api;		api.get({ action:'parse', text:'', contentmodel:'wikitext' })		.done(function(data){ if(!data.error) { $('#articleComments').before($(data.parse.text["*"])); }		});	}); }

// Small script to fix article comments links var inter = setInterval(function {	var userGroups = mw.config.get('wgUserGroups');	var canBlock = /sysop|util|staff|helper|global-discussions-moderator|wiki-manager|soap/.test(userGroups.join('\n'));	if ($('[class^="ReplyCreate_reply-create"]').length) {		clearInterval(inter);

function changeCommentLinks { $('span[class^="EntityHeader_header-details"] > div[class^="wds-avatar EntityHeader_avatar"] > a').each(function {				var user = $(this).attr('href').replace(/\/wiki\/(User:|Special:Contributions\/)/gi, ''),					isIP = /^(?:(?:\d{1,3}\.){3}\d{1,3}|([0-9A-F]{0,4}:){1,7}[0-9A-F]{0,4})(?:\/\d{2})?$/gi.test(user),					$link = $(this).parent.parent.children('a:last-of-type:not(.mw-user-anon-link)'),					$this = $(this);

$link .attr('href', '/wiki/Special:Contributions/' + user) .html(user);

$this.attr('href', '/wiki/Special:Contributions/' + user);

$link.after(					' (', $('', {						href: "/wiki/Message_wall:" + user,						html: "wall",						title: "Message_wall:" + user,						class: "mw-user-anon-link",					}), canBlock ? ' &bull; ' : "", canBlock ? $('', {						href: "/wiki/Special:Block/" + user,						html: "block",						title: "Special:Block/" + user,						class: "mw-user-anon-link",					}) : "", ')'				);			});		}

changeCommentLinks;

$('[class^="ReplyList_view-all-replies"]').click(function {			setTimeout(changeCommentLinks, 25);		}); } }, 25);

//############################################################## /* ==Element animator== (B00)*/ // Taken from https://minecraft.gamepedia.com/MediaWiki:Gadget-site.js /** * Element animator * * Cycles through a set of elements (or "frames") on a 2 second timer per frame * Add the "animated" class to the frame containing the elements to animate. * Optionally, add the "animated-active" class to the frame to display first. * Optionally, add the "animated-subframe" class to a frame, and the * "animated-active" class to a subframe within, in order to designate a set of * subframes which will only be cycled every time the parent frame is displayed. * Animations with the "animated-paused" class will be skipped each interval. * * Requires some styling in wiki's CSS. */

$( function {

( function {	var $content = $( '#mw-content-text' );	var advanceFrame = function( parentElem, parentSelector ) {		var curFrame = parentElem.querySelector( parentSelector + ' > .animated-active' );		$( curFrame ).removeClass( 'animated-active' );		var $nextFrame = $( curFrame && curFrame.nextElementSibling || parentElem.firstElementChild );		return $nextFrame.addClass( 'animated-active' );	};	// Set the name of the hidden property	var hidden; 	if ( typeof document.hidden !== 'undefined' ) {		hidden = 'hidden';	} else if ( typeof document.msHidden !== 'undefined' ) {		hidden = 'msHidden';	} else if ( typeof document.webkitHidden !== 'undefined' ) {		hidden = 'webkitHidden';	}	setInterval( function { if ( hidden && document[hidden] ) { return; }		$content.find( '.animated' ).each( function {			if ( $( this ).hasClass( 'animated-paused' ) ) {				return;			}			var $nextFrame = advanceFrame( this, '.animated' );			if ( $nextFrame.hasClass( 'animated-subframe' ) ) {				advanceFrame( $nextFrame[0], '.animated-subframe' );			}		} ); }, 2000 ); } );

/** * Pause animations on mouseover of a designated container (.animated-container and .mcui) * * This is so people have a chance to look at the image and click on pages they want to view. */ $( '#mw-content-text' ).on( 'mouseenter mouseleave', '.animated-container, .mcui', function( e ) {	$( this ).find( '.animated' ).toggleClass( 'animated-paused', e.type === 'mouseenter' ); } );

// A work around to force wikia's lazy loading to fire setTimeout(function{	$(".animated .lzy[onload]").load; }, 1000);

} );

//############################################################## /* ==Small scripts== (W00)*/

/* Used to move ID from onto a parent tr tag (if it exists), allowing the whole row to be styliszed in CSS (using the :target seloector) */ function _goToID(id) { $("html, body").animate({ scrollTop: $('#'+id).offset.top-65 }, 500); } $("tr .text-anchor").each(function{	var id = $(this).attr("id");	$(this).removeAttr("id");	$(this).closest("tr").attr("id", id);	// Re-trigger hash tag	if(location.hash.replace("#", "") === id) {		// Show table if collapsed:		var inCollapseTable = $(this).parents(".mw-collapsed");		setTimeout(function{ if(inCollapseTable.length) { var parentTable = $(inCollapseTable[0]); parentTable.removeClass("mw-collapsed"); parentTable.find("tr").stop.show; /*if(parentTable.hasClass("mw-made-collapsible")) { var collapseID = parentTable.attr("id").replace("mw-customcollapsible-", ""); $(".mw-customtoggle-"+collapseID).click; } else { parentTable.removeClass("mw-collapsed"); }*/			}			_goToID(id); }, 1000);	} });

$(window).on( 'hashchange', function(e) {	var hash = location.hash.replace("#", "");	$("tr[id]").each(function{ var $row = $(this); var id = $row.attr("id"); if(id === hash) { var inCollapseTable = $row.parents(".mw-collapsed"); if(inCollapseTable.length) { var $parentTable = $(inCollapseTable[0]); var collapseID = $parentTable.attr("id").replace("mw-customcollapsible-", ""); $(".mw-customtoggle-"+collapseID).click; }			_goToID(id); }	}); } );

$('a[href=\"#ajaxundo\"]').attr('title', 'Instantly undo this edit without leaving the page');

function changeLinks { $('a[href^="/wiki/Module_talk:"], a[href^="/wiki/Module talk:"]').each(function {		if ($(this).prop('href').match(/Module[_ ]talk:(.+?)\/doc/g)) {			$(this).html($(this).html.replace(/Module[ _]talk:(.+?)\/doc/g, 'Module documentation:$1'));		}	}); $('h3').each(function {		if ($(this).html.match(/Module[_ ]talk:(.+?)\/doc/g)) {			$(this).html($(this).html.replace(/Module[ _]talk:(.+?)\/doc/g, 'Module documentation:$1'));			$(this).attr('title', $(this).attr('title').replace(/Module[ _]talk:(.+?)\/doc/g, 'Module documentation:$1'));		}	}); } window.ajaxCallAgain = window.ajaxCallAgain || []; window.ajaxCallAgain.push(changeLinks);

$(document).ready(changeLinks);

/* Script to make page-specific styling */ $('#mw-content-text > .mw-parser-output').find('.pageStyles').each(function {	var $this = $(this);	var css = $this.text;	var id = $this.attr('id');	/* For security purposes, DO NOT REMOVE! */	function validateCSS(css) {		return css			.replaceAll(/([\t ]*)[a-z0-9\-]+\s*:.*url\(["']?(.*?)["']?\)[^;}]*;?[\t ]*/gi, '$1/* url is not allowed */') // url			.replaceAll(/([\t ]*)[a-z0-9\-]+\s*:.*expression\(["']?(.*?)["']?\)[^;}]*;?[\t ]*/gi, '$1/* expression is not allowed */') // expression			.replaceAll(/([\t ]*)@import.*/gi, "$1/* @import is not allowed */") // @import			.replaceAll(/([\t ]*)[a-z0-9\-]+\s*:[ \t]*["']?javascript:([^;\n]*)?;?[\t ]*/gi, '$1/* javascript: is not allowed */') // javascript:			.replaceAll(/^([\t ]*)@font-face\s*{[^\0]*}/gi, "$1/* @font-face is not allowed */"); // @font-face	}	$(' ', {		text: validateCSS(css),		type: "text/css",		class: $this.attr('class') && $this.attr('class').replaceAll(/^pageStyles\s*|pageStyles\s*$/g, ""), id: id, }).appendTo('head'); });

// Add profile links $(function {	if (mw.config.get('wgNamespaceNumber') !== 2 || mw.config.get('wgPageName').match('/')) return;	var userName = $("h1[itemprop=\"name\"]").html;	new mw.Api.get({ action: "query", list: "users", ususers: userName, }).then(function(d) { if (d.query.users[0].invalid !== undefined) return;

$(".user-identity-stats").append($('', { html: $('', {				href: "/f/u/" + d.query.users[0].userid,				html: $(' ', { text: "PROFILE" }),			}), }));	}); }); // Script to respond to ANI reports if (	mw.config.get('wgUserGroups').includes('bureaucrat', 'sysop') 	&& mw.config.get('wgPageName').includes('Administrator\'s_Noticeboard') 	&& mw.config.get('wgNamespaceNumber') === 4 ) $(".mw-editsection").append(' | ', $("", { class: "mw-complete-report", text: "mark as complete", title: "Mark this report as compelete", css: { cursor: "pointer", },		click: function { var user = $(this).parent.parent.next.children('li:first-of-type').children('a:first-of-type').html; var message = prompt('Enter a message to respond with:'); if (message === null) return; new mw.Api.postWithEditToken({				action: "edit",				appendtext: "\n: " + message + " ",				title: mw.config.get('wgPageName'),				summary: "Marking report of " + user + " as completed",				section: new mw.Uri($(this).parent.find('a[href*="&section="]').attr('href')).query.section,			}); },	}));

// Code to allow making clickable to show different content $(function{	if (!$(".sbw-ui-tabber").length) {		return;	}

// .hidden works on mobile, but not on desktop $(".sbw-ui-tab-content.hidden").hide; $(".sbw-ui-tabber .invslot").each(function{		var classes = Array.from($(this)[0].classList).filter(function(c) { return c.indexOf("goto-") === 0 || c.indexOf("ui-") === 0; });

if (classes.length) { var className = classes[(classes.length)-1] .replace("goto-", "") .replace("ui-", ""); $(this).click(function {				clickTab(className);			}); }	});	$(".sbw-ui-tabber .sbw-ui-tab").click(function(e) { e.preventDefault; e.stopImmediatePropagation; var id = $(this).data("tab"); if (id) { clickTab(id); }	});	function clickTab(id) {		id = "ui-"+id;		if(!$("#"+id).length) { console.warn("No such tab ID \"" + id + "\""); return; }		$(".sbw-ui-tab-content").addClass("hidden").hide;		$(".sbw-ui-tab-content#"+id).removeClass("hidden").show;		// Since images don't load on hidden tabs, force them to load		$(".sbw-ui-tab-content#"+id+" .lzy[onload]").load;	} });

if (mw.config.get('wgPageName').match(/^S:(.+)$/i)) { window.location.replace(mw.util.getUrl('Special:' + mw.config.get('wgPageName').match(/^S:(.+)$/i)[1])); }

if (mw.config.get('wgPageName').match(/^HSW:(.+)$/i) && mw.config.get('wgAction') === 'view') { window.location.replace(mw.util.getUrl('Project:' + mw.config.get('wgPageName').match(/^HSW:(.+)$/i)[1])); }

if (mw.config.get('wgPageName').match(/^MD:(.+)$/i) && mw.config.get('wgAction') === 'view') { window.location.replace(mw.util.getUrl('Module_talk:' + mw.config.get('wgPageName').match(/^MD:(.+)$/i)[1]) + '/doc'); }

//############################################################## /* ==importArticle pre-script actions== (X00)*/ // The code in this section is for a script imported below

// AjaxRC window.ajaxRefresh = 30000; window.ajaxPages = [ "Special:RecentChanges", "Special:WikiActivity", "Special:Watchlist", "Special:Log", "Special:Contributions", "Special:AbuseLog", ]; $.extend(true, window, {dev: {i18n: {overrides: {AjaxRC: {	'ajaxrc-refresh-text': 'Auto Refresh',	'ajaxrc-refresh-hover': 'Enable automatically refreshing of this page', }}}}});

//########################################### /* ===Less=== (X01) */

window.lessOpts = window.lessOpts || []; window.lessOpts.push( {	// this is the page that has the compiled CSS	target: 'MediaWiki:Common.css',	// this is the page that lists the LESS files to compile	source: 'MediaWiki:Custom-common.less',	// these are the pages that you want to be able to update the target page from	// note, you should not have more than one update button per page	load: [ 'MediaWiki:Common.css', 'MediaWiki:Custom-common.less' ],	// target page header	header: 'MediaWiki:Custom-css-header/common',	// allowed groups	allowed: [ 'codeeditor' ], } );

//########################################### /* ===UserTagsJS=== (X02) */ window.UserTagsJS = { modules: {}, tags: { rollback: {u: 'Rollback'}, mod: {u:'Mod'}, hypixelstaff: {u:'Hypixel Staff'}, juniorsysop: {u:'Junior Sysop'}, discord: {u:'Discord Server'}, templates: {u:'Templates'}, css: {u:'CSS'}, html: {u:'HTML'}, js: {u:'Java Script'}, lua: {u:'Lua'}, translator: {u: 'Translator'}, oldstaff: {u: 'Retired Staff'}, },	oasisPlaceBefore: '' };

UserTagsJS.modules.custom = { // Old Wiki Staff 'IcyOfficial': ['oldstaff', 'mod', 'discord'], '4hrue2kd83f': ['oldstaff', 'discord'], 'SirCowMC': ['oldstaff', 'hypixelstaff', 'discord'], // Admins 'Thundercraft5': ['templates', 'html', 'css', 'lua'], 'Joker876': ['templates', 'html', 'css', 'lua'], 'Fewfre': ['templates', 'html', 'css', 'lua', 'js'], 'Specter Elite': ['html', 'css', 'templates'], // Content Moderators 'Snoo999': ['templates', 'html', 'lua', 'css', 'translator'], 'Southmelon': ['templates', 'lua'], '100KPureCool': ['html', 'translator'], // Discussions Moderators 'Thecrazybone': ['rollback'], 'Bewioeop': ['rollback'], 'YakuzaMC': ['rollback'], // Ryanbansriyar: ['rollback'], <-- Disabled due to invite abuse // Rollbackers 'BigBoiSchmeedas': ['rollback'], 'BrandonXLF': ['rollback', 'lua', 'js'], 'Doej134567': ['rollback'], 'Fealtous': ['rollback'], 'Flachdachs': ['rollback', 'js'], 'Hexafish': ['rollback'], 'Lunatic Lunala': ['rollback'], 'OfTheAsh': ['rollback'], 'PaperAeroplane555': ['rollback'], 'Powman898': ['rollback'], 'Pwign': ['rollback', 'js', 'lua', 'templates'], 'SamuraiMosey': ['rollback'], 'Spectrogram': ['rollback'], // Users 'Eason329': ['translator'], 'HibiscusLavaR': ['translator'], 'DarkblueKR': ['translator'], 'EinsMarcel': ['translator'], };

//########################################### /* ===HighlightUsers=== (X03) */ window.highlightUsersConfig = { colors: { 'bureaucrat': '#ff4f52', 'bot': 'darkgray', 'sysop': '#7e2dbc', 'content-moderator': '#7FFFD4', 'threadmoderator': '#1f9921', 'rollback': '#ff992b', },	styles: { 'bureaucrat': 'text-shadow: 0 0 4px #c77979 !important;', 'bot': 'text-shadow: 0 0 3px gray !important;', 'sysop': 'text-shadow: 0 0 4px #7550ac !important;', 'content-moderator': 'text-shadow: 0 0 3px #397561 !important;', 'threadmoderator': 'text-shadow: 0 0 3px #648264 !important;', 'rollback': 'text-shadow: 0 0 4px #a36726 !important;', } };

//############################################################## /* ==importArticles== (Y00)*/ // Imports scripts from other pages/wikis. // NOTE: importAricles is currently broken. window.importScripts = function(pages) { if (!Array.isArray(pages)) { pages = [pages]; }

pages.forEach(function(v) {		var wiki;		var match = v.match(/^(?:u|url):(.+?):(.+)$/);		(match|| []).shift;		wiki = wiki || mw.config.get('wgServer').replace('https://', ).replace('.fandom.com', );		match = match || v;		$.getScript('https://' + (Array.isArray(match) ? match[0] : wiki) + '.fandom.com/wiki/' + (Array.isArray(match) ? match[1] : match) + '?action=raw&ctype=text/javascript')			.then(function { console.log(v + ': Imported Successfuly!'); });	}); };

importScripts([	"MediaWiki:Common.js/minetip.js",	"MediaWiki:Common.js/skydate.js",	"MediaWiki:Common.js/calc.js", ]);