MediaWiki:Common.js

From Discord Dungeons Wiki
Revision as of 16:08, 11 February 2020 by Mackan (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After saving, 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)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function(){
  document.querySelector(".adsbygoogle[data-ad-slot='4215338972']").style.width = "100%";

  (adsbygoogle = window.adsbygoogle || []).push({});

  document.querySelector(".adsbygoogle[data-ad-slot='2561978974']").style.width = "100%";

  (adsbygoogle = window.adsbygoogle || []).push({});

  document.querySelector(".adsbygoogle[data-ad-slot='8839171779']").style.width = "100%";

  (adsbygoogle = window.adsbygoogle || []).push({});


  // Analytics

  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    // Creates an adblock detection plugin.
    ga('provide', 'adblockTracker', function(tracker, opts) {
      var ad = document.createElement('ins');
      ad.className = 'AdSense';
      ad.style.display = 'block';
      ad.style.position = 'absolute';
      ad.style.top = '-1px';
      ad.style.height = '1px';
      document.body.appendChild(ad);
      tracker.set('dimension' + opts.dimensionIndex, !ad.clientHeight);
      document.body.removeChild(ad);
    });

  // UA-39978167-4

    ga('create', '', 'auto');
    ga('require', 'adblockTracker', {dimensionIndex: 1});
    ga('send', 'pageview');

    function fallback(){
      new Array().forEach.call(document.querySelectorAll(".ads"), function(el){
        el.innerHTML = "<span style='text-align:center;font-size:large;'>Ads suck, We know.<br>Discord Dungeons costs $800 a year to run.<br>Please disable your adblocker.</span>";
      })
    }

    if(typeof fuckAdBlock === 'undefined') {
      fallback();
    } else {
      fuckAdBlock.onDetected(fallback);
    }

    if(document.querySelector(".adsbygoogle").hidden || document.querySelector(".adsbygoogle").innerHTML.length <= 0){
      fallback();
    }
});


'use strict';(function(a){var b=function(c){this._options={checkOnLoad:!1,resetOnEnd:!1,loopCheckTime:50,loopMaxNumber:5,baitClass:'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links',baitStyle:'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;',debug:!1},this._var={version:'3.2.1',bait:null,checking:!1,loop:null,loopNumber:0,event:{detected:[],notDetected:[]}},c!==void 0&&this.setOption(c);var d=this,e=function(){setTimeout(function(){!0===d._options.checkOnLoad&&(!0===d._options.debug&&d._log('onload->eventCallback','A check loading is launched'),null===d._var.bait&&d._creatBait(),setTimeout(function(){d.check()},1))},1)};a.addEventListener===void 0?a.attachEvent('onload',e):a.addEventListener('load',e,!1)};b.prototype._options=null,b.prototype._var=null,b.prototype._bait=null,b.prototype._log=function(c,d){console.log('[FuckAdBlock]['+c+'] '+d)},b.prototype.setOption=function(c,d){if(d!==void 0){var e=c;c={},c[e]=d}for(var f in c)this._options[f]=c[f],!0===this._options.debug&&this._log('setOption','The option "'+f+'" he was assigned to "'+c[f]+'"');return this},b.prototype._creatBait=function(){var c=document.createElement('div');c.setAttribute('class',this._options.baitClass),c.setAttribute('style',this._options.baitStyle),this._var.bait=a.document.body.appendChild(c),this._var.bait.offsetParent,this._var.bait.offsetHeight,this._var.bait.offsetLeft,this._var.bait.offsetTop,this._var.bait.offsetWidth,this._var.bait.clientHeight,this._var.bait.clientWidth,!0===this._options.debug&&this._log('_creatBait','Bait has been created')},b.prototype._destroyBait=function(){a.document.body.removeChild(this._var.bait),this._var.bait=null,!0===this._options.debug&&this._log('_destroyBait','Bait has been removed')},b.prototype.check=function(c){if(void 0===c&&(c=!0),!0===this._options.debug&&this._log('check','An audit was requested '+(!0===c?'with a':'without')+' loop'),!0===this._var.checking)return!0===this._options.debug&&this._log('check','A check was canceled because there is already an ongoing'),!1;this._var.checking=!0,null===this._var.bait&&this._creatBait();var d=this;return this._var.loopNumber=0,!0===c&&(this._var.loop=setInterval(function(){d._checkBait(c)},this._options.loopCheckTime)),setTimeout(function(){d._checkBait(c)},1),!0===this._options.debug&&this._log('check','A check is in progress ...'),!0},b.prototype._checkBait=function(c){var d=!1;if(null===this._var.bait&&this._creatBait(),(null!==a.document.body.getAttribute('abp')||null===this._var.bait.offsetParent||0==this._var.bait.offsetHeight||0==this._var.bait.offsetLeft||0==this._var.bait.offsetTop||0==this._var.bait.offsetWidth||0==this._var.bait.clientHeight||0==this._var.bait.clientWidth)&&(d=!0),void 0!==a.getComputedStyle){var e=a.getComputedStyle(this._var.bait,null);e&&('none'==e.getPropertyValue('display')||'hidden'==e.getPropertyValue('visibility'))&&(d=!0)}!0===this._options.debug&&this._log('_checkBait','A check ('+(this._var.loopNumber+1)+'/'+this._options.loopMaxNumber+' ~'+(1+this._var.loopNumber*this._options.loopCheckTime)+'ms) was conducted and detection is '+(!0==d?'positive':'negative')),!0===c&&(this._var.loopNumber++,this._var.loopNumber>=this._options.loopMaxNumber&&this._stopLoop()),!0==d?(this._stopLoop(),this._destroyBait(),this.emitEvent(!0),!0===c&&(this._var.checking=!1)):(null===this._var.loop||!1===c)&&(this._destroyBait(),this.emitEvent(!1),!0===c&&(this._var.checking=!1))},b.prototype._stopLoop=function(){clearInterval(this._var.loop),this._var.loop=null,this._var.loopNumber=0,!0===this._options.debug&&this._log('_stopLoop','A loop has been stopped')},b.prototype.emitEvent=function(c){!0===this._options.debug&&this._log('emitEvent','An event with a '+(!0===c?'positive':'negative')+' detection was called');var d=this._var.event[!0===c?'detected':'notDetected'];for(var e in d)!0===this._options.debug&&this._log('emitEvent','Call function '+(parseInt(e)+1)+'/'+d.length),d.hasOwnProperty(e)&&d[e]();return!0===this._options.resetOnEnd&&this.clearEvent(),this},b.prototype.clearEvent=function(){this._var.event.detected=[],this._var.event.notDetected=[],!0===this._options.debug&&this._log('clearEvent','The event list has been cleared')},b.prototype.on=function(c,d){return this._var.event[!0===c?'detected':'notDetected'].push(d),!0===this._options.debug&&this._log('on','A type of event "'+(!0===c?'detected':'notDetected')+'" was added'),this},b.prototype.onDetected=function(c){return this.on(!0,c)},b.prototype.onNotDetected=function(c){return this.on(!1,c)},a.FuckAdBlock=b,a.fuckAdBlock===void 0&&(a.fuckAdBlock=new b({checkOnLoad:!0,resetOnEnd:!0}))})(window);



/**
 * Dynamic Navigation Bars. See [[Wikipedia:NavFrame]]
 * 
 * Based on script from en.wikipedia.org, 2008-09-15.
 *
 * @source www.mediawiki.org/wiki/MediaWiki:Gadget-NavFrame.js
 * @maintainer Helder.wiki, 2012–2013
 * @maintainer Krinkle, 2013
 */
( function () {

window.hasClass = function( element, className ) {
    return $( element ).hasClass( className );
}

// Set up the words in your language
var collapseCaption = 'hide';
var expandCaption = 'show';

var navigationBarHide = '[' + collapseCaption + ']';
var navigationBarShow = '[' + expandCaption + ']';

/**
 * Shows and hides content and picture (if available) of navigation bars.
 *
 * @param {number} indexNavigationBar The index of navigation bar to be toggled
 * @param {jQuery.Event} e Event object
 */
function toggleNavigationBar( indexNavigationBar, e ) {
	var navChild,
		navToggle = document.getElementById( 'NavToggle' + indexNavigationBar ),
		navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );

	// Prevent browser from jumping to href "#"
	e.preventDefault();

	if ( !navFrame || !navToggle ) {
		return false;
	}

	// If shown now
	if ( navToggle.firstChild.data == navigationBarHide ) {
		for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) {
			if ( hasClass( navChild, 'NavPic' ) ) {
				navChild.style.display = 'none';
			}
			if ( hasClass( navChild, 'NavContent' ) ) {
				navChild.style.display = 'none';
			}
		}
		navToggle.firstChild.data = navigationBarShow;

	// If hidden now
	} else if ( navToggle.firstChild.data == navigationBarShow ) {
		for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) {
			if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
				navChild.style.display = 'block';
			}
		}
		navToggle.firstChild.data = navigationBarHide;
	}
}

/**
 * Adds show/hide-button to navigation bars.
 *
 * @param {jQuery} $content
 */
function createNavigationBarToggleButton( $content ) {
	var i, j, navFrame, navToggle, navToggleText, navChild,
		indexNavigationBar = 0,
		navFrames = $content.find( 'div.NavFrame' ).toArray();

	// Iterate over all (new) nav frames
	for ( i = 0; i < navFrames.length; i++ ) {
		navFrame = navFrames[i];
		// If found a navigation bar
		indexNavigationBar++;
		navToggle = document.createElement( 'a' );
		navToggle.className = 'NavToggle';
		navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
		navToggle.setAttribute( 'href', '#' );
		$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );

		navToggleText = document.createTextNode( navigationBarHide );
		for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) {
			if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
				if ( navChild.style.display == 'none' ) {
					navToggleText = document.createTextNode( navigationBarShow );
					break;
				}
			}
		}

		navToggle.appendChild( navToggleText );
		// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
		for ( j = 0; j < navFrame.childNodes.length; j++ ) {
			if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
				navFrame.childNodes[j].appendChild( navToggle );
			}
		}
		navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
	}
}

mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );

}());