Utilisateur:Od1n/MediaWiki:Gadget-ExtendedArchiveLinks.js

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.
/**
 * Variante du script de cache étendant le script
 * à tous les liens externes et à tous les espaces de noms.
 *
 * <!--{{Catégorisation JS|ExtendedArchiveLinks}}-->
 */
function extendedArchiveLinks(element) {

    element = element || document;
    $(element).find('a.external').each(function () {

        var $this = $(this);
        var chemin = this.href;

        if (/(^|\.)wiki[pm]edia\.org$/.test(this.hostname)
        || chemin.indexOf('http://archive.wikiwix.com/cache/') === 0
        || chemin.indexOf('http://wikiwix.com/cache/') === 0
        || chemin.indexOf('http://web.archive.org/web/') === 0) {
            return;
        }

        if ($this.parents().hasClass('noarchive')) {
            return;
        }

        // sécurité : attention à échapper les quotes dans les attributs

        var href = 'http://archive.wikiwix.com/cache/?url=' + encodeURIComponent(chemin);
        var title = 'archive de ' + $this.text().replace(/"/g, '&quot;');

        var link = '<a href="' + href + '" title="' + title + '">archive</a>';

        $this.after('<small class="cachelinks">\u00a0[' + link + ']</small>');
    });
}

$(function ($) {
    extendedArchiveLinks();
});