User:--miki--/global.js

ShoutWiki — express yourself and be heard!
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 / Edge: 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.
/**
 * For action=purge to index.php
 *   change it to POST api.php
 *   then reload the page
 * Restores pre-1.28 behavior to MW 1.28+
 * Based on meta:User:Glaisher/autoPurge.js, 21 Aug 2016
 */
if (( mw.config.get( 'wgAction' ) === 'purge' ) &&
	( $.inArray( 'user', mw.config.get( 'wgUserGroups' )) + 1 )) {
	$.post( mw.config.get( 'wgScriptPath' ) + '/api.php', {
		format: 'none',
		action: 'purge',
		titles: mw.config.get( 'wgPageName' ).replace( /_/g, ' ' )
	}, function () {
		// remove action=purge, but keep the rest
		location.replace(
			location.pathname +
			location.search
				.replace( /(?:\?|&)action=purge$/i, '' )
				.replace( /(\?|&)action=purge&/i, '$1' ) +
			location.hash
		);
	} );
}

/**
 * Sometimes I have to view individual pages in different skins.
 * Add links to use different skins instead of typing the URL manually.
 */
mw.loader.using( 'mediawiki.api', function() {
	if ( mw.config.get( 'wgAction' ) !== 'view' ) {
		return;
	}

	var api = new mw.Api();
	var page = encodeURIComponent( mw.config.get( 'wgPageName' ) );
	var links = '';
	
	api.get( {
		action: 'query',
		format: 'json',
		meta: 'siteinfo',
		siprop: 'skins'
	} ).done( function (data) {
		data.query.skins.forEach( function( value ) {
			skin = value.code;
			if ( skin !== mw.config.get( 'skin' ) && skin !== 'fallback' && skin !== 'apioutput' ) {
				links = links + '<li id="n-' + skin + '"><a href="/wiki/' + page + '?useskin=' + skin + '">' + value['*'] + '</a></li>';
			}
		} );
		appendSkinLinks( links );
	} );
} );

function appendSkinLinks( links ) {
	if ( mw.config.get( 'skin' ) === 'aurora' ) {
		$( '#p-toolbox .p-menu-inner' ).append( '<h5>Skins</h5><ul id="p-skins" class="p-menu-items"></ul>' );
		$( '#p-skins' ).append( links );
	} else if ( mw.config.get( 'skin' ) === 'modern' ) {
		$( '#mw_portlets' ).append( '<div id="p-skins" class="portlet"><h3>Skins</h3><div class="pBody"><ul></ul></div></div>' );
		$( '#p-skins ul' ).append( links );
	} else if ( mw.config.get( 'skin' ) === 'monaco' ) {
		$( '#sidebar_2' ).append( '<dl id="WidgetSkins" class="widget"><dt class="color1">Skins</dt><dd><ul></ul></dd></dt></dl>' );
		$( '#WidgetSkins ul' ).append( links );
	} else if ( mw.config.get( 'skin' ) === 'monobook' ) {
		$( '#sidebar' ).append( '<div id="p-skins" class="portlet"><h3>Skins</h3><div class="pBody"><ul></ul></div></div>' );
		$( '#p-skins ul' ).append( links );
	} else if ( mw.config.get( 'skin' ) === 'nimbus' ) {
		$( '#search-box .bottom-left-nav' ).append( '<div id="p-skins" class="bottom-left-nav-container"><h2>Skins</h2><div><ul></ul></div></div>' );
		$( '#p-skins ul' ).append( links );
	} else if ( mw.config.get( 'skin' ) === 'refreshed' ) {
		$( '#sidebar' ).append( '<section id="p-skins" class="sidebar-section"><h1 class="main">Skins</h1><ul><ul></ul></ul></section>' );
		$( '#p-skins ul ul' ).append( links );
	} else if ( mw.config.get( 'skin' ) === 'timeless' ) {
		$( '#site-tools .sidebar-inner' ).append( '<div id="p-skins" class="mw-portlet"><h3>Skins</h3><div class="mw-portlet-body"><ul></ul></div></div>' );
		$( '#p-skins ul' ).append( links );
	} else if ( mw.config.get( 'skin' ) === 'truglass' ) {
		$( '#sidebar' ).append( '<div id="sbm-skins" class="sbmodule"><h4 class="sbmoduletitle">Skins</h4><div class="sbmodulebody"><div><ul></ul></div></div></div>' );
		$( '#sbm-skins ul' ).append( links );
	} else if ( mw.config.get( 'skin' ) === 'vector' ) {
		$( '#mw-panel' ).append( '<div id="p-skins" class="portal"><h3>Skins</h3><div class="body"><ul></ul></div></div>' );
		$( '#p-skins ul' ).append( links );
	}
}