MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */	$(document).ready(function {		//OOUI-based tabber		mw.hook( "wikipage.content" ).add( function ($content) { var $tabberElements = $content.find( ".no-history-tabber" ); if ($tabberElements.length > 0) { //Only load the modules and run the Javascript if there is a fehwiki-tabber in the page. mw.loader.using("oojs-ui-widgets").then(function {					var TABBER_HEADER_CLASS = "no-history-tab-header";					var TABBER_HEADER_CLASS_SELECTOR = "."+TABBER_HEADER_CLASS;					var CSS_END_REGEX = /;\s*$/;					var uniqueNumber = 0;					var INDEX_LAYOUT_OPTIONS = {						classes: ['no-history-tabber-index'],						expanded: false,						autoFocus: false					};					$tabberElements.each( function(_, ele) { var tabPanelLayouts = []; var $rootTabberElement; var indexLayout = new OO.ui.IndexLayout(INDEX_LAYOUT_OPTIONS); $( ele ).children( TABBER_HEADER_CLASS_SELECTOR ).each( function (_, tabHeaderEle) {							var contents = [];							$( tabHeaderEle ).nextUntil( TABBER_HEADER_CLASS_SELECTOR ).each( function(_, node) { contents.push(node); } );							tabPanelLayouts.push(new OO.ui.TabPanelLayout(tabHeaderEle.textContent + uniqueNumber++, {								classes: ['no-history-tabber-tab'],								expanded: false,								label: new OO.ui.HtmlSnippet(tabHeaderEle.innerHTML),								content: contents							}));						} ); indexLayout.addTabPanels(tabPanelLayouts); if ($(ele).attr("data-tab-default") !== undefined) { const activeTabIdx = parseInt($(ele).attr("data-tab-default")) - 1; if (!isNaN(activeTabIdx) && activeTabIdx >= 0 && activeTabIdx < tabPanelLayouts.length) { indexLayout.setTabPanel(tabPanelLayouts[activeTabIdx].name); }						}						$rootTabberElement = (new OO.ui.PanelLayout( { classes: ['no-history-tabber-panel'], expanded: false, content: [ indexLayout ] })).$element; //If it has one, adds the inline style the fehwiki-tabber div element has to the new tabber element $rootTabberElement.attr( "style", function(_, attr) {							var s = $( ele ).attr( "style" );							return attr ? s + (CSS_END_REGEX.test(attr) ? "" : ";") + attr : s;						} ); $( ele ).replaceWith( $rootTabberElement ); });				});			}		} );		//End tabber	}); /**	 * Countdown *	 * @version 2.1 *	 * @author Pecoes  * @author Asaba  *	 * Version 1 authors: * - Splarka  * - Eladkse  *	 * documentation and examples at: *  */	/*jshint jquery:true, browser:true, devel:true, camelcase:true, curly:false, undef:true, bitwise:true, eqeqeq:true, forin:true, immed:true, latedef:true, newcap:true, noarg:true, unused:true, regexp:true, strict:true, trailing:false */ /*global mediaWiki:true*/ ;(function (module, mw, $, undefined) {		'use strict';		var translations = $.extend(true, { // English (English) en: { and: 'and', second: 'second', seconds: 'seconds', minute: 'minute', minutes: 'minutes', hour: 'hour', hours: 'hours', day: 'day', days: 'days' }		}, module.translations || {}),		i18n = translations[			mw.config.get('wgContentLanguage')		] || translations.en;		var countdowns = [];		var NO_LEADING_ZEROS = 1,		SHORT_FORMAT = 2,		NO_ZEROS = 4;		function output (i, diff) {			/*jshint bitwise:false*/			var delta, result, parts = [];			delta = diff % 60;			result = ' ' + i18n[delta === 1 ? 'second' : 'seconds'];			if (countdowns[i].opts & SHORT_FORMAT) result = result.charAt(1);			parts.unshift(delta + result);			diff = Math.floor(diff / 60);			delta = diff % 60;			result = ' ' + i18n[delta === 1 ? 'minute' : 'minutes'];			if (countdowns[i].opts & SHORT_FORMAT) result = result.charAt(1);			parts.unshift(delta + result);			diff = Math.floor(diff / 60);			delta = diff % 24;			result = ' ' + i18n[delta === 1 ? 'hour'  : 'hours'  ];			if (countdowns[i].opts & SHORT_FORMAT) result = result.charAt(1);			parts.unshift(delta + result);			diff = Math.floor(diff / 24); result = ' ' + i18n[diff === 1 ? 'day'   : 'days'   ]; if (countdowns[i].opts & SHORT_FORMAT) result = result.charAt(1); parts.unshift(diff + result); result = parts.pop; if (countdowns[i].opts & NO_LEADING_ZEROS) { while (parts.length && parts[0][0] === '0') { parts.shift; }			}			if (countdowns[i].opts & NO_ZEROS) { parts = parts.filter(function(part) {					return part[0] !== '0';				}); }			if (parts.length) { if (countdowns[i].opts & SHORT_FORMAT) { result = parts.join(' ') + ' ' + result; } else { result = parts.join(', ') + ' ' + i18n.and + ' ' + result; }			}			countdowns[i].node.text(result); }		function end(i) { var c = countdowns[i].node.parent; switch (c.attr('data-end')) { case 'remove': c.remove; return true; case 'stop': output(i, 0); return true; case 'toggle': var toggle = c.attr('data-toggle'); if (toggle && toggle == 'next') { c.next.css('display', 'inline'); c.css('display', 'none'); return true; }				if (toggle && $(toggle).length) { $(toggle).css('display', 'inline'); c.css('display', 'none'); return true; }				break; case 'callback': var callback = c.attr('data-callback'); if (callback && $.isFunction(module[callback])) { output(i, 0); module[callback].call(c); return true; }				break; }			countdowns[i].countup = true; output(i, 0); return false; }		function update { var now = Date.now; var countdownsToRemove = []; $.each(countdowns.slice(0), function (i, countdown) {				var diff = Math.floor((countdown.date - now) / 1000);				if (diff <= 0 && !countdown.countup) {					if (end(i)) countdownsToRemove.push(i);				} else {					output(i, Math.abs(diff));				}			}); var x;			while((x = countdownsToRemove.pop) !== undefined) { countdowns.splice(x, 1); }			if (countdowns.length) { window.setTimeout(function {					update;				}, 1000); }		}		function getOptions (node) { /*jshint bitwise:false*/ var text = node.parent.attr('data-options'), opts = 0; if (text) { if (/no-leading-zeros/.test(text)) { opts |= NO_LEADING_ZEROS; }				if (/short-format/.test(text)) { opts |= SHORT_FORMAT; }				if (/no-zeros/.test(text)) { opts |= NO_ZEROS; }			}			return opts; }		function init { var countdown = $('.countdown:not(.handled)'); if (!countdown.length) return; $('.nocountdown').css('display', 'none'); countdown .css('display', 'inline') .find('.countdowndate') .each(function {				var $this = $(this),					date = (new Date($this.text)).valueOf;				if (isNaN(date)) {					$this.text('BAD DATE');					return;				}				countdowns.push({ node: $this, opts: getOptions($this), date: date, });			});			countdown.addClass('handled'); if (countdowns.length) { update; }		}		mw.hook('wikipage.content').add(init); }(window.countdownTimer = window.countdownTimer || {}, mediaWiki, jQuery));	// End Countdown })(mediaWiki, jQuery);
 * (function(mw, $) {

//Experimental Js for countdown clock. change the //date as appropriate. //the if statement is mandatory so the script only runs //on a page that has this specific element.

function getHour(hourCD){ if(hourCD > 9) {return(hourCD);} else {return(" 0" + hourCD);} } function getMinute(minuteCD){ if(minuteCD > 9) {return(minuteCD);} else {return(" 0" + minuteCD);} } function getSecond(secondCD){ if(secondCD > 9) {return(secondCD);} else {return(" 0" + secondCD);} }

if(document.querySelector("#countdown-clock .arrival-time")){ const clock = document.querySelector("#countdown-clock"); const arrival = document.querySelector("#countdown-clock .arrival-time"); const month = document.querySelector("#countdown-clock .month"); const date = document.querySelector("#countdown-clock .date"); const hour = document.querySelector("#countdown-clock .hour"); const minute = document.querySelector("#countdown-clock .minute"); const second = document.querySelector("#countdown-clock .second"); const timeAndBg = clock.classList;

clock.style.backgroundImage = "url(" + timeAndBg[4] + ")";

var timeArrival = new Date; timeArrival.setUTCFullYear(parseInt(timeAndBg[0])); //change all this timeArrival.setUTCMonth(parseInt(timeAndBg[1])); //to the time in UTC till timeArrival.setUTCDate(parseInt(timeAndBg[2])); //next update is online. timeArrival.setUTCHours(parseInt(timeAndBg[3]), 0, 0, 0); //format : HH, MM, SS, msms arrival.innerHTML = "Update Time : " + timeArrival; var now = new Date; var timeDiff = 1;

const intervalId = setInterval(function { now = new Date;

timeDiff = (timeArrival.getFullYear - now.getFullYear)*12*30*24*60*60 + (timeArrival.getMonth - now.getMonth)*30*24*60*60 + (timeArrival.getDate - now.getDate)*24*60*60 + (timeArrival.getHours - now.getHours)*60*60 + (timeArrival.getMinutes - now.getMinutes)*60 + (timeArrival.getSeconds - now.getSeconds); if(timeDiff >= 0) { yearCD = Math.floor(timeDiff/12/30/24/60/60); monthCD = Math.floor(timeDiff/30/24/60/60); dayCD = Math.floor(timeDiff/24/60/60 - monthCD*30); hourCD = Math.floor(timeDiff/60/60 - monthCD*30*24 - dayCD*24); minuteCD = Math.floor(timeDiff/60 - monthCD*30*24*60 - dayCD*24*60 - hourCD*60); secondCD = Math.floor(timeDiff - monthCD*30*24*60*60 - dayCD*24*60*60 - hourCD*60*60 - minuteCD*60); month.innerHTML = monthCD; date.innerHTML = dayCD; hour.innerHTML = getHour(hourCD); minute.innerHTML = getMinute(minuteCD); second.innerHTML = getSecond(secondCD); } }, 1000);

if(timeDiff < 0) { clearInterval(intervalId); }}

/* SCRIPTS*/ mw.loader.load('//dev.miraheze.org/w/index.php?title=MediaWiki:MultiUpload.js&action=raw&ctype=text/javascript'); mw.loader.load('//dev.miraheze.org/w/index.php?title=MediaWiki:MassDelete.js&action=raw&ctype=text/javascript');

//audioplayer start var audioplayerz = document.getElementsByClassName("audio-button"); var audioPlayer = function { var audioplayerx = this; var audioplayery = audioplayerx.getElementsByTagName("audio")[0]; if (audioplayery.paused) { var audio = document.getElementsByTagName('audio'), audioplayeri = audio.length; while (audioplayeri--) { audio[audioplayeri].pause; audio[audioplayeri].currentTime = 0; }		var audioplayerj = document.getElementsByClassName("audio-button playing"); while(audioplayerj.length > 0) { audioplayerj[0].className = 'audio-button'; }	   audioplayery.play; audioplayerx.className = "audio-button playing"; audioplayery.addEventListener("timeupdate", audioUpdate, false); audioplayery.addEventListener("canplaythrough", function {			audioplayerd = audioplayery.duration;		}, false); } else { audioplayery.pause; audioplayery.currentTime = 0; audioplayerx.className = "audio-button"; } }; function audioUpdate { if (this.currentTime == audioplayerd) { this.parentElement.className = "audio-button" this.removeEventListener('timeupdate', audioUpdate, false); } } for (var audioplayeri = 0; audioplayeri < audioplayerz.length; audioplayeri++) { audioplayerz[audioplayeri].addEventListener('click', audioPlayer, false); }

$('.audio-button a.new').parent.addClass('no-audio'); //audioplayer end

/** * JS Tab System, jacked and hacked from the jsprefs in wikibits.js * * Original code by Dantman * Refactored a bit by Jack Phoenix on 11 April 2014 * Support for linking to a particular tab by MatmaRex on 30 December 2016. * @note Should be rewritten to properly use jQuery like how mediawiki.special.preferences.js does. */ var TabSystem = { /**	 * @property {boolean} * Is the user's browser a KHTML-based one (usually, but not always, Konqueror)? */	isKHTML: ( navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ) ), /**	 * @property {boolean} * Is the user's browser Opera? */	isOpera: navigator.userAgent.toLowerCase.indexOf( 'opera' ) != -1, /*		Written by Jonathan Snook, http://www.snook.ca/jonathan Add-ons by Robert Nyman, http://www.robertnyman.com Author says "The credit comment is all it takes, no license. Go crazy with it!:-)"		From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/	*/	getElementsByClassName: function( oElm, strTagName, oClassNames ) {		var arrReturnElements = [];		if ( typeof oElm.getElementsByClassName == 'function' ) {			/* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */			var arrNativeReturn = oElm.getElementsByClassName( oClassNames );			if ( strTagName == '*' ) {				return arrNativeReturn;			}			for ( var h = 0; h < arrNativeReturn.length; h++ ) {				if ( arrNativeReturn[h].tagName.toLowerCase == strTagName.toLowerCase ) {					arrReturnElements[arrReturnElements.length] = arrNativeReturn[h];				}			}			return arrReturnElements;		}		var arrElements = ( strTagName == '*' && oElm.all ) ? oElm.all : oElm.getElementsByTagName( strTagName );		var arrRegExpClassNames = []; if ( typeof oClassNames == 'object' ) { for ( var i = 0; i < oClassNames.length; i++ ) { arrRegExpClassNames[arrRegExpClassNames.length] = new RegExp( "(^|\\s)" + oClassNames[i].replace( /\-/g, "\\-" ) + "(\\s|$)" ); }		} else { arrRegExpClassNames[arrRegExpClassNames.length] = new RegExp( "(^|\\s)" + oClassNames.replace( /\-/g, "\\-" ) + "(\\s|$)" ); }		var oElement; var bMatchesAll; for ( var j = 0; j < arrElements.length; j++ ) { oElement = arrElements[j]; bMatchesAll = true; for ( var k = 0; k < arrRegExpClassNames.length; k++ ) { if ( !arrRegExpClassNames[k].test( oElement.className ) ) { bMatchesAll = false; break; }			}			if ( bMatchesAll ) { arrReturnElements[arrReturnElements.length] = oElement; }		}		return arrReturnElements; },	/**	 * Main function that performs all the magic on all div elements that have * class="tab" and are inside a div that has class="tabcontainer". */	main: function { var tabcontainers = TabSystem.getElementsByClassName( document, 'div', 'tabcontainer' ); for ( var tc = 0; tc < tabcontainers.length; tc++ ) { if ( !tabcontainers[tc] || !document.createElement ) { return; }			if ( tabcontainers[tc].nodeName.toLowerCase == 'a' ) { return; // Occasional IE problem }			tabcontainers[tc].className += ' jstabs'; var sections = []; var children = tabcontainers[tc].childNodes; var seci = 0; for ( var i = 0; i < children.length; i++ ) { if ( children[i].className && children[i].className.match( /tab/i ) ) { children[i].id = 'tabsection-' + seci + '-' + tc; children[i].className += ' tabsection'; // Opera and KHTML-based browsers get a special class if ( TabSystem.isOpera || TabSystem.isKHTML ) { children[i].className += ' tabsection operatabsection'; }					var legends = TabSystem.getElementsByClassName( children[i], 'div', 'tab' ); sections[seci] = {}; legends[0].className = 'mainTab'; if ( legends[0] && legends[0].firstChild.nodeValue ) { sections[seci].text = legends[0].firstChild.nodeValue; } else { sections[seci].text = '# ' + seci; }					sections[seci].secid = children[i].id; seci++; if ( sections.length != 1 ) { children[i].style.display = 'none'; } else { var selectedid = children[i].id; }				}			}			var toc = document.createElement( 'ul' ); toc.className = 'tabtoc'; toc.id = 'tabtoc-' + tc; toc.selectedid = selectedid; for ( i = 0; i < sections.length; i++ ) { var li = document.createElement( 'li' ); if ( i === 0 ) { li.className = 'selected'; }				var a = document.createElement( 'a' ); a.href = '#' + sections[i].secid; a.appendChild( document.createTextNode( sections[i].text ) ); a.secid = sections[i].secid; li.appendChild( a ); toc.appendChild( li ); // Capture current value of variables in the closure ( function ( i, a ) {					$( window ).on( 'hashchange', function { if ( location.hash === '#' + sections[i].secid ) { TabSystem.uncoverTabSection( toc, a ); }					} )					if ( location.hash === '#' + sections[i].secid ) {						TabSystem.uncoverTabSection( toc, a );					}				} )( i, a ); }			tabcontainers[tc].parentNode.insertBefore( toc, tabcontainers[tc] ); }	},	/**	 * Show the contents of a tab section when the user clicks on the tab. *	 * @return {boolean} Always false */	uncoverTabSection: function( ul, a ) { var oldsecid = ul.selectedid; var newsec = document.getElementById( a.secid ); if ( oldsecid != a.secid ) { document.getElementById( oldsecid ).style.display = 'none'; newsec.style.display = 'block'; ul.selectedid = a.secid; var lis = ul.getElementsByTagName( 'li' ); for ( var i = 0; i < lis.length; i++ ) { lis[i].className = ''; }			a.parentNode.className = 'selected'; }		return false; } }; // Attach the onload handler using jQuery. $( function {	TabSystem.main; } );

/** * Unwatch from watchlist * * Add an "unwatch" link near each entry on the watchlist view (424). * * @source https://www.mediawiki.org/wiki/Snippets/Unwatch_from_watchlist * @author Krinkle * @revision 2016-09-01 */ mw.hook( 'wikipage.content' ).add( function ( $content ) {	// Only on Watchlist and not in the /edit or /raw mode	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Watchlist' || location.href.indexOf( '/edit' ) > 0 || location.href.indexOf( '/raw' ) > 0 ) {		return;	}	mw.loader.using( ['mediawiki.util', 'mediawiki.api.watch'] ).then( function { // Get the links var $wlHistLinks = $content.find( 'ul.special .mw-changeslist-line .mw-changeslist-history');

$wlHistLinks.each( function {			var $unwatch,				$el = $( this ),				title = mw.util.getParamValue( 'title', this.href );

$unwatch = $el.clone .text( 'unwatch' ) .attr( 'href', function ( i, val ) {					return val.replace( 'action=history', 'action=unwatch' );				} ) .on( 'click', function ( e ) {					new mw.Api.unwatch( title )						.done( function { $unwatch.css( { pointerEvents: 'none', opacity: 0.5 } ); } )						.fail( function { $unwatch.off( 'click' ).append( ' (try again?)' ); } );					e.preventDefault;				} ); $el.after( $unwatch ).after( ' | ' ); } );	} ); } );