User:Equazcion/SidebarTranslate.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Equazcion/SidebarTranslate and an accompanying .css page at User:Equazcion/SidebarTranslate.css. |
var plang = $('#p-lang').hide();
$(document).ready( function() {
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 ) {
importStylesheet('User:Equazcion/SidebarTranslate.css');
var langReg = /(.*? – )?(.*)/;
var gtPre = 'http://translate.google.com/translate?hl=en&sl=auto&tl=en&u=';
var hardLangs = {
'lumbaart': 'Lombard',
'tarandíne': 'Tarantino',
'vèneto': 'Venetian',
'Беларуская (тарашкевіца)': 'Belarusian (Taraškievica)',
'буряад': 'Buryat',
'лакку': 'Lak'
};
var googleSupported = ['Afrikaans', 'Albanian', 'Arabic', 'Armenian', 'Azerbaijani', 'Basque', 'Belarusian', 'Bengali', 'Bulgarian',
'Catalan', 'Chinese', '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();
var langMatches = langReg.exec( $this.attr('title') );
if ( langMatches != null ) {
var newLangName = (langMatches[2] in hardLangs) ? hardLangs[ langMatches[2] ] : langMatches[2];
if ( $this.attr('hreflang') == 'be-x-old' ) newLangName = 'Belarusian (Taraškievica)'; // Doesn't match object key for some reason
var hrefs = $this.attr('href');
var origLangPre = (langMatches[1] == undefined) ? '' : langMatches[1];
$this.text( newLangName ).removeAttr('lang style').attr( 'title', origLangPre + origLangName );
var unsup = ( googleSupported.indexOf(langMatches[2]) < 0 ) ? '#FA8540' : '#4085FA';
$('<a/>', {
'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(' ', '<br />') );
$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();
});