Jump to content

User:Ian Splinter/interwiki.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Ian Splinter (talk | contribs) at 08:22, 20 June 2010 (script). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
//------------------------------------------------------------------------------------

// Script plaatst interwiki's naar grotere Wikipedia's indien aanwezig bovenaan

// (Duits, Engels, Frans, Italiaans, Portugees, Spaans, Fins, Noors, Pools en Zweeds)

// Tevens enkele aan het Nederlands verwante talen

// (Afrikaans, Fries, Limburgs, Nedersaksisch, West-Vlaams en Zeeuws)

//

// Based on script found on [[:nn:MediaWiki/monobook.js]]

// Maintainers: [[:no:User:Jeblad]], fix voor nl: [[nl:User:Zanaq]]

//

// Indien andere talen gewenst het script kopiëren en de talen achter prefs= aanpassen

// Voeg de code importScript('Gebruiker:Troefkaart/interwiki.js'); toe aan monobook.js

// Vervang Troefkaart door eigen naam bij kopiëren gehele code

//

// Door bv li.interwiki-de, li.interwiki-en { font-weight: bold; } in het monobook.css 

// te plaatsen worden interwiki's naar aangegeven talen vet gemaakt.

// Werkt ook zonder dit script

// ik (Ian) heb dit gecopieerd van troefkaart

//------------------------------------------------------------------------------------ 

 

  addOnloadHook( function () {

 

      //if (!prefs) return;

      prefs=["nl", "en", "de"]

 

      var iwlinks = [];

      for (i=0;i<prefs.length;i++) {

          iwlinks["interwiki-" + prefs[i]] = 1;

      }

      var container = document.getElementById("p-lang");

 

      if (!container) return;

 

      var keeps = Array();

      var ul = container.getElementsByTagName("ul");

      if (!ul) return;

      if (ul.length != 1) return;

      ul = ul[0];

      var childs = container.getElementsByTagName("li");

      for (i=0;i<childs.length;i++) {

          // the following test fails if there are several classes for the actual child

 if ( iwlinks[ childs[i].getAttribute( 'class' ) ] ) {

     keeps.push(childs[i]);

          }

      }

      var n = childs.length;

      for (i=childs.length-1;i>=0;i--) {

 if ( !iwlinks[ childs[i].getAttribute( 'class' ) ] ) {

     keeps[--n] = childs[i];

          }

          else {

              childs[i].setAttribute( 'class', childs[i].getAttribute( 'class' ) + ' iw-focus' );

          }

      }

 

      var child;

      while (child = ul.firstChild) {

          ul.removeChild(child);

      }

      for (i=0;i<keeps.length;i++) {

          ul.appendChild(keeps[i]);

      }

  });