MediaWiki:Gadget-sidebarTranslate.js

// By Equazcion: http://terraria.gamepedia.com/User:Equazcion

mw.util.addCSS(	'.gTrans:hover { text-decoration:none; }' +	'#p-lang ul { width:115%; } ' +	'#p-lang li.interlanguage-link { font-family: inherit; }' +	'.gTrans { ' +		'display: none; ' +		'font-family: serif; ' +		'cursor: pointer; ' +		'color: white; ' +		'background-color: transparent;' +		'border-radius: 2px; ' +		'padding: 0 2px; ' +		'margin-left: 5px; ' +		'transition:' +			'margin-left 200ms ease-out, ' +			'background-color 100ms ease-out, ' +			'color 100ms ease-out; ' +	'} ' );

var plang = $('#p-lang').hide;

function sort( a, b ) { return ( $(b).text ) < ( $(a).text ) ? 1 : -1; } var plangUL = plang.find('ul'); var interwikis = plangUL.find('li[class^="interlanguage-link"]').detach; if ( interwikis.length > 0 ) { var gtPre = 'http://translate.google.com/translate?hl=en&sl=auto&tl=en&u='; var hardLangs = { '中文':'Chinese', '中文（中国大陆）‎':'Chinese (Simplified)', 'Français':'French', '한국어':'Korean', 'Polski':'Polish', 'Português':'Portuguese', 'Русский':'Russian', 'Čeština':'Czech', 'Deutsch':'German', 'Español':'Spanish', 'Magyar':'Hungarian', 'Bahasa Indonesia':'Indonesian', 'Italiano':'Italian', 'Lietuvių':'Lithuanian', 'Latviešu':'Latvian', 'Nederlands':'Dutch', 'Türkçe':'Turkish', 'Українська':'Ukrainian' };	var googleSupported = ['Afrikaans', 'Albanian', 'Arabic', 'Armenian', 'Azerbaijani', 'Basque', 'Belarusian', 'Bengali', 'Bulgarian', 'Catalan', 'Chinese', 'Chinese (Simplified)', 'Croatian', 'Czech', 'Danish', 'Dutch', 'English', 'Esperanto', 'Estonian', 'Filipino', 'Finnish', 'French', 'Galician', 'Georgian', 'German', 'Greek', 'Haitian', 'Creole', 'Hebrew', 'Hindi', 'Hungarian', 'Icelandic', 'Indonesian', 'Irish', 'Italian', 'Japanese', 'Javanese', 'Kannada', 'Korean', 'Khmer', 'Latin', 'Latvian', 'Lithuanian', 'Macedonian', 'Malay', 'Maltese', 'Marathi', 'Norwegian', 'Norwegian (bokmål)', 'Norwegian Nynorsk', 'Persian', 'Polish', 'Portuguese', 'Romanian', 'Russian', 'Serbian', 'Slovak', 'Slovenian', 'Spanish', 'Swahili', 'Swedish', 'Tamil', 'Telugu', 'Thai', 'Turkish', 'Ukrainian', 'Urdu', 'Vietnamese', 'Welsh', 'Yiddish']; interwikis.find('a').each( function {		var $this = $(this);		var origLangName = $this.text;		if ( origLangName != null ) {			var newLangName = hardLangs[ origLangName ];			var hrefs = $this.attr('href');			$this.text( newLangName ).removeAttr('lang style');			var unsup = ( googleSupported.indexOf(newLangName) < 0 ) ? '#FA8540' : '#4085FA';			$('', { 'text': 'G', 'class': 'external gTrans', 'target': '_blank', 'href': gtPre + hrefs, 'title': 'Google Translate: ' + newLangName + ' to English', 'style': 'color:' + unsup + ';' }).insertAfter( $this ).before(' ');			if ( $this.text.length > 17 ) $this.html( $this.html.replace('-','- ').replace(' ', ' ') );			$this.siblings('.gTrans').hover( function { $(this).css( {'background-color': unsup, 'color': 'white'} ) }, function { $(this).css( {'background-color': 'transparent', 'color': unsup} ) } );			$this.parent('li').hover( function { $(this).find('.gTrans').fadeIn(200).css('margin-left','0') }, function { $(this).find('.gTrans').fadeOut(100).css('margin-left','5px') } );		}	});	plangUL.prepend( interwikis.sort(sort) ); } plang.show;