User:Majr/scriptLoader.js

( function( mcw ) { 'use strict';

if ( !mcw.scriptLoaderPages ) { return; }

var options = [ $( ' ' ).text( 'Select script' ).css( 'display', 'none' ) ]; $.each( mcw.scriptLoaderPages, function {	options.push( $( ' ' ).text( this ) ); } );

var loading; $( '.netbar-right' ).prepend( $( '' ).append( $( ' ' ).addClass( 'script-loader' ).on( 'change', function {		var $select = $( this );		var page = $select.val;		if ( page.match( /^\// ) ) {			page = 'User:' + mw.config.get( 'wgUserName' ) + page;		}		var url = ( mcw.scriptLoaderUrl || '' ) + mw.config.get( 'wgScript' ) + '?' + $.param( { title: page, action: 'raw', ctype: 'text/javascript' } );		$.when( loading ).done( function { loading = $.getScript( url ).done( function {				$select.val( 'Select script' );			} ); } );	} ).append( options ) ) );

}( window.mcw || {} ) );