Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js

MediaWiki interface page
Revision as of 09:51, 8 September 2025 by MTOnline (talk | contribs) (added element animator)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

var ads = [
	"AD_Hat.png",
	"AD_Aura.png",
	"AD_Pass_BB.png",
	"AD_Pass_HITW.png",
	"AD_Pass_PKW.png",
	"AD_Pass_SB.png",
	"AD_Pass_TGTTOS.png",
	"AD_Boosts_1.png",
	"AD_Boosts_2.png",
	"AD_Cactus_Ranger.png",
	"AD_Candlewick.png",
	"AD_Construction_Chaos.png",
	"AD_Looter_Extraordinaire.png",
	"AD_Masco_Head.png",
	"AD_Battle_Pass_1.png",
	"AD_Battle_Pass_2.png",
	"AD_Battle_Pass_3.png",
];

// Get the ad
var adName = ads[Math.floor(Math.random() * ads.length)];
// Get footer
var footer = document.getElementsByClassName('citizen-footer__content')[0];

// Store Link
var link = document.createElement("a");
link.href = "https://store.mccisland.net/?utm_source=mccisland.wiki&utm_campaign=wiki_ads";
link.target = "_blank";
link.rel = "noreferrer noopener";
link.className = "citizen-footer__ad";
footer.append(link);

// Ad image
var ad = document.createElement("img");
ad.src = mw.util.getUrl("Special:Redirect/file/" + adName);
link.append(ad);


/* Fires when DOM is ready */
$( function() {


/**
 * 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 from [[MediaWiki:Common.css]].
 * Originally from https://minecraft.wiki/w/MediaWiki:Gadget-site.js
 */
( 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 );
}() );


} );
/* End DOM ready */