User:Jack Phoenix/monobook.js

From translatewiki.net
Jump to: navigation, 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.
/**
 * Array.indexOf() polyfill from MDN to support IE8
 * @see http://stackoverflow.com/questions/3629183/why-doesnt-indexof-work-on-an-array-ie8
 */
if ( !Array.prototype.indexOf ) {
	Array.prototype.indexOf = function( elt /*, from*/ ) {
		var len = this.length >>> 0;

		var from = Number( arguments[1] ) || 0;
		from = ( from < 0 ) ? Math.ceil( from ) : Math.floor( from );
		if ( from < 0 ) {
			from += len;
		}

		for ( ; from < len; from++ ) {
			if ( from in this && this[from] === elt ) {
				return from;
			}
		}
		return -1;
	};
}

$( document ).ready( function() {
	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Translate' ) {
		/**
		 * Show the _full_, untruncated message (well, wiki page if we're being exact)
		 * name on Special:Translate, i.e. MediaWiki:Some_message/fi instead of
		 * ...ssage/fi
		 */
		$( 'tr td > a[title^="Edit"]' ).each( function( index ) {
			var foo = $( this ).attr( 'title' ).replace( /Edit \"/, '' );
			foo = foo.replace( /\"/, '' );
			$( this ).text( foo );
		} );

		/**
		 * Force Special:Translate to render in classical mode, always, no matter what
		 */
		if ( mw.util.getParamValue( 'tux' ) === null ) {
			if ( window.location.indexOf( '?' ) != 1 ) {
				window.location = window.location + '&tux=0';
				window.location.reload( true );
			} else {
				window.location = window.location + '?tux=0';
				window.location.reload( true );
			}
		} // if no tux param in URL
	} // if Special:Translate

	/**
	 * Ensure that all links to Special:Translate contain the tux=0 parameter
	 */
	$( 'a[href^="/wiki/Special:Translate"], a[href^="//translatewiki.net/w/i.php?title=Special:Translate"]' ).each( function() {
		$( this ).attr( 'href', function( i, h ) {
			return h + ( h.indexOf( '?' ) != -1 ? '&tux=0' : '?tux=0' );
		} );
	} );
} );