MediaWiki:Common.js

From Ymirheim Wiki

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. */
(function(){
	var doc = document.getElementById('mw-content-wrapper');
	if (doc) {
		doc.style = 'padding-top: 48px;';
		var a = document.createElement('a');
		a.href="https://supportukrainenow.org/";
		a.target="_blank";
		a.rel = "noindex nofollow";
		a.style = 'display: block; margin: 20px 0;';
		var img = document.createElement('img');
		img.src = "https://ymirheim.org/files/images/19ee4f9fe1e6a0c3286d40c55f5c80465fadad01.png";
		img.style = 'width: 100%; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);';
		img.alt = "";
		a.append(img);
		doc.insertBefore(a, doc.firstChild);
	}
	
	// Fix same-domain links that are marked as external
	mw.hook( 'wikipage.content' ).add( function( $content ) {
		$content.find( 'a.external, a[rel="mw:ExtLink"]' ).each( function () {
			// Can't use wgServer because it can be protocol relative
			// Use this.href property instead of this.getAttribute( 'href' ) because the property
			// is converted to a full URL (including protocol)
			if ( this.href.indexOf( location.protocol + '//' + location.hostname ) === 0 ) {
				this.target = '_self';
			}
		} );
	} );
	
	jQuery(function($) {
		// Localized homepage link
		$('a#p-banner').each(function() {
			var href = $(this).attr('href');
			href = href.replace(/(\w+)$/, "Special:MyLanguage/$1");
			$(this).attr('href', href);
		});
		
		// Level Infoboxes
		var levelInfoboxesWrapper = $('.level-infoboxes');
		if (levelInfoboxesWrapper.length > 0) {
			var levelInfoboxes = levelInfoboxesWrapper.find('.level-infobox');
			
			// Show first infobox
			if (levelInfoboxes.length > 0) {
				levelInfoboxes.first().show();
			}
			
			// Navigation buttons
			levelInfoboxesWrapper.find('.prev-level, .next-level').click(function(e) {
				var levelInfobox = $(this).closest('.level-infobox');
				var isNext = $(this).is('.next-level');
				var level = parseInt(levelInfobox.data('level'));
				var targetLevel = isNext ? level+1 : level-1;
				var targetLevelInfobox = levelInfoboxesWrapper.find('.level-infobox[data-level="' + targetLevel + '"]');
				if (targetLevelInfobox.length > 0) {
					levelInfoboxes.hide();
					targetLevelInfobox.show();
				}
			});
		}
		
		// Fix for intorrect source language links in the interwiki section.
		$('.interlanguage-link-target[lang="en"]').each(function() {
			var href = $(this).attr('href');
			href = href.replace(/\/en$/i, '');
			$(this).attr('href', href);
		});
		
		// Fix for Popups not showing the previews for 'Special:MyLanguage' links.
		var wgContentNamespaces = mw.config.get('wgContentNamespaces');
		wgContentNamespaces.push(-1);
		mw.config.set('wgContentNamespaces', wgContentNamespaces);
		
		if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
			$(document.body).addClass('prefers-color-scheme-dark');
		}
	});
})();