User:Frog23/MyInterwikiLinks.js

Source: 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.
/*
	(English Description see below)

	Script My_Interwiki_Links für Wikipedia
	=======================================

	Dies ist ein Script, das die Interwiki-Links zu den Sprachen, die
	man selbst versteht, an den Anfang der Interwiki-Linkliste setzt.

	Konfiguration:
	Füge diese Zeile in die JavaScript-Seite deiner Skin ein, bevor du
	dieses Script einbindest:

		 var myInterwikiLinks_languages = new Array("en","fr","it");
	
	In diesem Beispiel werden die Interwiki-Links zu Sprachen Englisch, 
	Französisch und Italienisch an den Anfang der Interwiki-Linkliste
	gesetzt. Die Sprachkürzel können durch beliebige andere ersetzt und
	es können beliebig viele anderen hinzugefügt oder entfernt werden.


	Script My_Interwiki_Links for Wikipedia
	=======================================
	
	A script which puts the interwiki links to languages you understand 
	at the beginning of the list of interwiki links.
	
	Configuration: 
	Add a line like the following to the JavaScript-Page of your Skin 
	before you call this script:
	
		var myInterwikiLinks_languages = new Array("de","fr","it");
	
	In this example the interwiki-links for the languages German, French 
	and Italian are placed at the beginning of the list of interwiki-links. 
	You can change the languages, add or remove as many as you like.

	
	Author: Frog23 <http://de.wikipedia.org/wiki/Benutzer:Frog23>
	
	Copyright (C) 2010  

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

if(!MyInterwikiLinks) var MyInterwikiLinks = {};

MyInterwikiLinks = {
	// with the default setting without configuration just the English interwiki link will be displayed seperately
	languages:new Array("en"),
	
	changeLinkOrder: function(){
		//check if 
		if (typeof myInterwikiLinks_languages === 'undefined') {
			myInterwikiLinks_languages = MyInterwikiLinks.languages;
		}		
		MyInterwikiLinks.languages = myInterwikiLinks_languages;
		
		var firstItemReplaced = false
		
		//get the list of interwiki links
		var plang = document.evaluate("id('p-lang')//ul", document, null, 9, null).singleNodeValue;
		
		if(plang){
			var length = MyInterwikiLinks.languages.length;
			for (var i = 0; i < length; i++) {
				//search for the links in the specified languages
				var interwikiLink = document.evaluate("id('p-lang')//li[starts-with(@class, 'interwiki-"+MyInterwikiLinks.languages[length-1-i]+"')]", document, null, 9, null).singleNodeValue;
				
				if(interwikiLink){
					//place the language link at the beginning of the list of interwiki links
					plang.insertBefore(interwikiLink,plang.firstChild);
					
					if(!firstItemReplaced){
						firstItemReplaced = true;
						//show a little spacer to the rest of the interwiki links
						interwikiLink.style.paddingBottom = "15px";
					}
				}
			}
		}
	}
};

$(MyInterwikiLinks.changeLinkOrder);