MediaWiki:Gadget-ArchiveLinks.js
Apparence
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./**
* Application de [[Wikipédia:Prise de décision/Système de cache]].
* Un <span class="noarchive"> autour d'un lien l'empêche d'être pris en compte.
*
* {{Catégorisation JS|ArchiveLinks}}
*/
if ( !window.no_external_cache && ( mw.config.get( 'wgNamespaceNumber' ) === 0 || mw.user.options.get( 'gadget-ExtendedCache' ) ) ) {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
var hasNativeClosest = !!Element.prototype.closest;
$content.find( '.mw-parser-output' ).find( '.external' ).each( function ( _, link ) {
if ( link.tagName !== 'A' ) {
return;
}
var chemin = link.href;
if ( /(^|\.)wiki([pm]edia|data)\.org$/.test( link.hostname )
|| chemin.indexOf( 'http://tools.wmflabs.org/' ) === 0
|| 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 ( hasNativeClosest ) {
if ( link.closest( '.noarchive, .infobox_v3' ) ) {
return;
}
} else {
if ( $( link ).closest( '.noarchive, .infobox_v3' ).length ) {
return;
}
}
// sécurité : attention à échapper les quotes dans les attributs
var href = 'http://archive.wikiwix.com/cache/?url=' + encodeURIComponent( chemin );
var title = 'archive sur Wikiwix';
var archiveLink = '<a href="' + href + '" title="' + title + '">archive</a>';
link.insertAdjacentHTML( 'afterend', '<small class="cachelinks">\u00a0[' + archiveLink + ']</small>' );
});
});
}