User:Grutness/common.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
importScript("User:Writ Keeper/Scripts/orangeBar.js");

if ( mw.config.values.wgCanonicalSpecialPageName === 'Whatlinkshere' ) {
	$( function() {
		'use strict';
		var ul = $( '#mw-whatlinkshere-list' );
		ul.before( '<button id="whatlinksheresort">Sort</button>' );
		$( '#whatlinksheresort' ).click( function() {
			var li = ul.children( 'li' );
			li.detach().sort( function( a, b ) {
				return $( a ).find( 'a' ).first().text().localeCompare( $( b ).find( 'a' ).first().text() );
			} );
			ul.append( li );
		} );
	} );
}