Utilisateur:Pmartin/cache.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) ;

Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
addOnloadHook(function () {
  if (mw.config.get('wgNamespaceNumber') == 0) {
    if ((typeof no_external_cache != "undefined") && (no_external_cache)) return;
    addcache();
  }
 
  function addcache() {
    var external_links = document.querySelectorAll('a.external');
 
    if (external_links.length > 50) return;
 
    for( i = 0;i < external_links.length;i++) 
    {
      var chemin = external_links[i].href;
 
      if(chemin.indexOf("http://wikiwix.com/cache/")==-1 && chemin.indexOf("http://web.archive.org/web/*/")==-1 && chemin.indexOf("wikipedia.org")==-1)
      {
      var li = external_links[i].parentNode;
      var depth = 0;
      while ((depth < 3) && (li.tagName != "LI") && (li.parentNode != null)) {
        li = li.parentNode;
        depth++;
      }
 
      if (li.tagName != "LI") continue;
 
      var last = document.createElement("small");
      last.setAttribute("class", "cachelinks");
      last.style.color = "#3366BB";
      last.appendChild(document.createTextNode("\u00a0["));
 
      var link = document.createElement("a");
      link.setAttribute("href", "http://wikiwix.com/cache/?url=" + chemin.replace(/&/g, "%26"));
      link.setAttribute("title", "archive sur Wikiwix");
      link.appendChild(document.createTextNode("archive"));
      link.style.color = "#3366BB";
      last.appendChild(link);
      last.appendChild(document.createTextNode("]"));

      $(last).insertAfter(external_links[i]);
      }
    }
  }

}
);