Aller au contenu

Utilisateur:Guillaumito/external.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.
/**
 * Modifie Special:Search pour pouvoir utiliser différents moteurs de recherche,
 * disponibles dans une boîte déroulante.
 * Auteurs : Jakob Voss, Guillaume, importé depuis la Wiki allemande
 * <pre><nowiki>
 */

function externalSearchEnginesDebug() {
  if (typeof SpecialSearchEnhanced2Disabled != 'undefined') return;
  if (mw.config.get('wgPageName') != "Spécial:Recherche") return;

  var mainNode = document.getElementById("powersearch");
  if (!mainNode) mainNode = document.getElementById("search");
  if (!mainNode) return;

  var beforeNode = document.getElementById("mw-search-top-table");
  if (!beforeNode) return;
  beforeNode = beforeNode.nextSibling;
  if (!beforeNode) return;
 
  var firstEngine = "mediawiki";
 
  var choices = document.createElement("div");
  choices.setAttribute("id","searchengineChoices");
  choices.style.textAlign = "center";
 
  var lsearchbox = document.getElementById("searchText");
  var initValue = lsearchbox.value;
 
  var space = "";

  for (var id in searchEngines) {
    var engine = searchEngines[id];
if(engine.ShortName)
   {
    if (space) choices.appendChild(space);
    space = document.createTextNode(" ");
 
    var attr = { 
      type: "radio", 
      name: "searchengineselect",
      value: id,
      onFocus: "changeSearchEngine(this.value)",
      id: "searchengineRadio-"+id
    };
 
    var html = "<input";
    for (var a in attr) html += " " + a + "='" + attr[a] + "'";
    html += " />";
    var span = document.createElement("span");
    span.innerHTML = html;
 
    choices.appendChild( span );
    var label
    if (engine.Template.indexOf('http') == 0) {
      label = document.createElement("a");
      label.href = engine.Template.replace("{searchTerms}", initValue).replace("{language}", "fr");
    } else {
      label = document.createElement("label");
    }
  
    label.appendChild( document.createTextNode( engine.ShortName ) );
    choices.appendChild( label );
  }
 }
  mainNode.insertBefore(choices, beforeNode);
 
  var input = document.createElement("input");
  input.id = "searchengineextraparam";
  input.type = "hidden";
 
  mainNode.insertBefore(input, beforeNode);

  changeSearchEngine(firstEngine, initValue);
}

function changeSearchEngine(selectedId, searchTerms) {

  var currentId = document.getElementById("searchengineChoices").currentChoice;
  if (selectedId == currentId) return;
 
  document.getElementById("searchengineChoices").currentChoice = selectedId;
  var radio = document.getElementById('searchengineRadio-'  + selectedId);
  radio.checked = "checked";
 
  var engine = searchEngines[selectedId];
  var p = engine.Template.indexOf('?');
  var params = engine.Template.substr(p+1);
 
  var form;
  if (document.forms["search"]) {
    form = document.forms["search"];
  } else {
    form = document.getElementById("powersearch");
  }
  form.setAttribute("action", engine.Template.substr(0,p));
 
  var l = ("" + params).split("&");
  for (var idx = 0;idx < l.length;idx++) {
    var p = l[idx].split("=");
    var pValue = p[1];
 
    if (pValue == "{language}") {
    } else if (pValue == "{searchTerms}") {
      var input;
      input = document.getElementById("searchText");
 
      input.name = p[0];
    } else {
      var input = document.getElementById("searchengineextraparam");
 
      input.name = p[0];
      input.value = pValue;
    }
  }
}

if (mw.config.get('wgPageName') == "Spécial:Recherche") {
var searchEngines = {
  mediawiki: {
    ShortName: "Recherche interne",
    Template: "/w/index.php?search={searchTerms}"
  },
  exalead: {
    ShortName: "Exalead",
    Template: "http://www.exalead.com/wikipedia/results?q={searchTerms}&language=fr"
  },
  google: {
    ShortName: "Google",
    Template: "http://www.google.fr/search?as_sitesearch=fr.wikipedia.org&hl={language}&q={searchTerms}"
  },
  wikiwix: {
    ShortName: "Wikiwix",
    Template: "http://fr.wikiwix.com/index.php?action={searchTerms}&lang={language}"
  },
 
  wlive: {
    ShortName: "Windows Live",
    Template: "http://search.live.com/results.aspx?q={searchTerms}&q1=site:http://fr.wikipedia.org"
  },
  yahoo: {
    ShortName: "Yahoo!",
    Template: "http://fr.search.yahoo.com/search?p={searchTerms}&vs=fr.wikipedia.org"
  },
globalwpsearch: {
    ShortName: "Global WP",
    Template: "http://vs.aka-online.de/cgi-bin/globalwpsearch.pl?timeout=120&search={searchTerms}"
  }
};
$(externalSearchEnginesDebug);
}