Utilisateur:Tavernier/sous1/JS

Un article de Wikipédia, l'encyclopédie libre.

//

  1. var cookieCacheRechercheExterneName = "cacheRechercheExterne";
  2. var urls = new Array();
  3.  
  4. function ExternalSearch() { //génère le contenu
  5.   if (wgPageName != "Utilisateur:Tavernier/sous1") return;
  6.   var mainNode = document.getElementById("searchbox");
  7.   if (!mainNode) return;
  8.  
  9.   var c = 0;
  10.   function CreateButton(name,value,parent,url) {
  11.     var button = document.createElement("input");
  12.     button.type = "button";
  13.     button.value = value;
  14.     button.setAttribute('onclick','SearchRedir(' + c + ');');
  15.     parent.appendChild(button);
  16.  
  17.     urls[c] = url;
  18.     c++;
  19.   }
  20.  
  21.   var span = document.createElement("span");
  22.   span.style.fontSize = "smaller";
  23.  
  24.   var a = document.createElement("a");
  25.   a.href="javascript:affRechercheExterne(true);";
  26.   a.id = "AfficheRechercheExterne";
  27.   a.title = "En raison des limitations du moteur de recherche interne, des boutons vers des moteurs externes vous sont temporairement proposés afin de vous aider dans vos recherches";
  28.   a.style.marginLeft = "1ex";
  29.   a.appendChild(document.createTextNode(">>"));
  30.   span.appendChild(a);
  31.  
  32.   var a = document.createElement("a");
  33.   a.href="javascript:affRechercheExterne(false);";
  34.   a.id = "CacheRechercheExterne";
  35.   a.style.marginLeft = "1ex";
  36.   a.appendChild(document.createTextNode("<<"));
  37.   span.appendChild(a);
  38.  
  39.   getElementsByClass("searchboxSearchButton")[0].parentNode.appendChild(span);
  40.  
  41.   var div = document.createElement("div");
  42.   div.id = "BoutonsRechercheExterne";
  43.  
  44.   CreateButton('exalead','Exalead', div, "http://www.exalead.fr/wikipedia/results?$mode=+csource/15985787839675132773&q=");
  45.   CreateButton('google','Google', div, "http://www.google.fr/search?as_sitesearch=fr.wikipedia.org&q=");
  46.   CreateButton('wikiwix','Wikiwix', div, "http://fr.wikiwix.com/?lang=fr&action=");
  47.   CreateButton('live','Windows Live', div, "http://search.live.com/results.aspx?q1=site:fr.wikipedia.org&q=");
  48.   CreateButton('yahoo','Yahoo!', div, "http://fr.search.yahoo.com/search?vs=fr.wikipedia.org&p=");
  49.  
  50.   mainNode.appendChild(div);
  51.  
  52.   affRechercheExterne((getCookieVal(cookieCacheRechercheExterneName) != "1"));
  53. }
  54.  
  55. function affRechercheExterne(visible) { //affiche / masque les boutons
  56.     var date = new Date();
  57.     var val = visible ? "=0" : "=1";
  58.     date.setTime(date.getTime() + 30*86400*1000);
  59.     document.cookie = cookieCacheRechercheExterneName + val + "; expires="+date.toGMTString() + "; path=/";
  60.     document.getElementById('BoutonsRechercheExterne').style.display = visible ? 'block' : 'none';
  61.     document.getElementById('CacheRechercheExterne').style.display = visible ? 'inline' : 'none';
  62.     document.getElementById('AfficheRechercheExterne').style.display = visible ? 'none' : 'inline';
  63. }
  64.  
  65. function SearchRedir(index) { //lance recherche externe suite pression sur bouton
  66.   window.location.href = urls[index] + escape(getElementsByClass("searchboxInput")[0].value);
  67. }
  68. addOnloadHook(ExternalSearch);
  69. //