Utilisateur:Kosame/monobook.js

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

Note : Après avoir publié la page, vous devrez forcer son rechargement pour voir les changements : Mozilla / Konqueror / Firefox : Shift-Ctrl-R, Internet Explorer / Opera : Ctrl-F5, Safari : Cmd-R.

/**
 * Bistro du jour
 *
 * Lien vers le bistro du jour dans le panneau de navigation
 *
 * Auteur : ??
 * Contributeur : Tieno, Maloq
 * Dernière révision : 22 avril 2008
 * [[Catégorie:MediaWiki:Fonction Monobook en JavaScript]]
 */
 
function TodayDate() {
      var m = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
      var today = new Date();
      var day = today.getDate();
      var year = today.getYear();
 
      if (year < 2000)
           year = year + 1900;
 
      return (day + " " + m[today.getMonth()] + " " + year);
}
 
function BistroDuJour()
{
  var a = document.getElementById("p-navigation");
  if (a)
  {
    var b = a.getElementsByTagName("ul");
    if(b.length > 0)
    {
      b[0].innerHTML = b[0].innerHTML
      + '<li><span id="n-bistro" title="Wikipédia:Le Bistro">'
      + '<a href="/wiki/Wikipédia:Le_Bistro/' + TodayDate() + '">Bistro du jour</a>'
      + '</span></li>';
    }
  }
}
 
addOnloadHook(BistroDuJour);
 
/**
 * GoogleSearch
 *
 * Bouton de recherche dans Google
 * 
 * Auteur : Pabix
 * Dernière révision : 10 novembre 2006
 * [[Catégorie:MediaWiki:Fonction Monobook en JavaScript]]
 */
 
//////////////////////ZONE PERSONNALISABLE//////////////////////
/* Serveur Google préféré */ var googlesearchPrefix = "com";
/////////////////FIN DE LA ZONE PERSONNALISABLE/////////////////
 
function GoogleSearch(){
        var sb = document.getElementById("searchBody");
        if (sb) {
                var input = document.createElement("input");
                with(input) {
                        setAttribute("type", "hidden");
                        setAttribute("name", "q");
                }
                var button = document.createElement("button");
                button.innerHTML="Google";
                button.setAttribute("class", "searchButton");
                var form = document.createElement("form");
                with(form) {
                        setAttribute("action", "http://www.google." + googlesearchPrefix + "/search");
                        setAttribute("method", "GET");
                        setAttribute("onsubmit", 'this.q.value=document.getElementById("searchInput").value + " site:fr.wikipedia.org";return true;');
                        appendChild(input);
                        appendChild(button);
                }
                sb.appendChild(form);
        }
}
addOnloadHook(GoogleSearch);
 
/**
 * Historique amélioré
 *
 * Indique le nombre de caractères ajoutés/supprimés à la place de la taille de la version,
 * comme pour la Liste de suivi ou les Modifications récentes.
 *
 * Auteur : The RedBurn
 *
 * Date de dernière révision : 21 mai 2007
 * [[Catégorie:MediaWiki:Fonction Monobook en JavaScript]]
 */
 
function getNumFromString (i,eltsByTag) {
  var regString = /\((.*) bytes\)/;
  var resultString;
  var string = eltsByTag.item(i).innerHTML;
  var separator = /[^0-9]/g;
  var empty = "(empty)";
 
  if(wgUserLanguage == "fr")
  {
    regString = /\((.*) octets\)/;
    empty = "(vide)";
  }
 
  if(string==empty)
    string=0;
  else {
    resultString= regString.exec(string);
    string = resultString[1].replace(separator,"");
    string = parseInt(string );
  }
  return string;
}
 
function makeNumDiff() {
  var string;
  var resultPrevString = 0; // précédent dans l'ordre chronologique
  var resultNextString = 0;
  var className;
  var lastI = 0;
  var i = 0;
  var eltsByTag = document.getElementsByTagName("span");
  var length = eltsByTag.length;
 
  while(i<length && eltsByTag.item(i).className != "history-size")
    i++;
 
  if(i<length) {
    resultNextString = getNumFromString(i,eltsByTag);
    lastI = i;
    i++;
 
    while (i<length) {
      if (eltsByTag.item(i).className == "history-size"){
 
        resultPrevString = getNumFromString(i,eltsByTag);
 
        string = resultNextString - resultPrevString;
 
        if (string>0) {
          className = "mw-plusminus-pos";
          string = "+" + string;
        }
        else
          if (string<0)
            className = "mw-plusminus-neg";
          else
            className = "mw-plusminus-null";
 
        if (string<-500)
          string = "<strong>" + "(" + string + ")" + "</strong>";
        else
          string = "(" + string + ")";
 
        eltsByTag.item(lastI).innerHTML = string ;
        eltsByTag.item(lastI).className = className;
 
        resultNextString = resultPrevString;
        lastI = i;
      }
      i++;
    }
  }
}
if(wgAction && wgAction == "history")
  addOnloadHook(makeNumDiff);