Aller au contenu

Utilisateur:Pmartin/WikiwixSearch exp.js

Une page de Wikipédia, l'encyclopédie libre.
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
function addWikiwixSearch() {
  if ( "Search" != mw.config.get('wgCanonicalSpecialPageName')  ) return //seulement actif dans special:Search
  //prepare not to add user defined ones.
  if ( "object" == typeof addWikiwixSearch_exclude  ) {
     var exclude = addWikiwixSearch_exclude.toString()
  } else {
     var exclude = 'x'
  }

  
  var compteur = 0;
 
  var addWikiwixSearch_icons = new Array()
  
  if ( -1 == exclude.search(/timeline/i) ) {
      addWikiwixSearch_icons[compteur] = new Array()
      addWikiwixSearch_icons[compteur]['link'] = "http://search.wikiwix.com/timeline.php?title="
      addWikiwixSearch_icons[compteur]['linkimg'] = "http://www.wikiwix.com/people/timeline/icon.png.php?title="
      addWikiwixSearch_icons[compteur]['linkalt'] = "Frise pour "
      addWikiwixSearch_icons[compteur++]['linkclass'] = "friseLink"
   }
 
  if ( -1 == exclude.search(/autour de/i) ) {
      addWikiwixSearch_icons[compteur] = new Array()
      addWikiwixSearch_icons[compteur]['link'] = "http://fr.wikiwix.com/index.php?lang=fr&disp=article&action=url:http://fr.wikipedia.org/wiki/"
      addWikiwixSearch_icons[compteur]['linkimg'] = "http://fr.wikiwix.com/images/puce_connex.png?x=" //x= car le titre est ajouté au bout de l'URL 
      addWikiwixSearch_icons[compteur]['linkalt'] = "Autour de "
      addWikiwixSearch_icons[compteur++]['linkclass'] = "autourDeLink"
  }
 
  if ( -1 == exclude.search(/atlas/i) ) {
      addWikiwixSearch_icons[compteur] = new Array()
      addWikiwixSearch_icons[compteur]['link'] = "http://www.wikiwix.com/index.php?atlas=true&map=true&lang=fr&action="
      addWikiwixSearch_icons[compteur]['linkimg'] = "http://www.wikiwix.com/people/atlas/icon.png.php?title="
      addWikiwixSearch_icons[compteur]['linkalt'] = "Atlas pour "
      addWikiwixSearch_icons[compteur++]['linkclass'] = "atlasLink"
  }
 
  if( 0 == compteur) return; //user want to see nothing. let's move along.
 
  var resultDiv = document.getElementsByClassName("mw-search-results")
  if ( 0 == resultDiv.length ) return; //pas de resultats
 
  var linesList = resultDiv[0].getElementsByTagName("li")
 
  for (var a=0 ; a<linesList.length ; a++) { 
     var afterText = linesList[a].getElementsByTagName("div")[0] //<- ne marche pas sous IE6
     var nom = linesList[a].getElementsByTagName("a")[0].title
 
     for (var id in addWikiwixSearch_icons) {
        var icone = addWikiwixSearch_icons[id]
        var img = document.createElement( "img" )
        img.src = icone['linkimg'] + nom
 
        var linkAdd = document.createElement('a')
        linkAdd.href = icone['link'] + nom
        linkAdd.target = "_blank"
        linkAdd.className = icone['linkclass']
        linkAdd.alt = icone['linkalt'] + nom
        linkAdd.appendChild( img )
 
        afterText.parentNode.insertBefore(linkAdd, afterText) //inserer le lien
     }
  }
}
$(addWikiwixSearch);
 
/* add the id of what you do not want to see in this array
var addWikiwixSearch_exclude = new Array(
   'timeline',
   'autour de',
   'atlas'
);
*/