MediaWiki:Gadget-ArchiveLinks.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.
/**
 * 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 ) {
		'use strict';

		$content.find( '.mw-parser-output' ).find( '.external' ).each( function ( _, link ) {
			if ( link.tagName !== 'A' ) {
				return;
			}

			var hostname = link.hostname;

			if ( /(^|\.)wiki([pm]edia|data)\.org$/.test( hostname )
				|| hostname === 'tools.wmflabs.org'
				|| hostname === 'archive.wikiwix.com' 
				|| hostname === 'wikiwix.com'
				|| hostname === 'web.archive.org'
				|| /^archive\.(is|ph|today|li|vn|fo|md)$/.test( hostname )
			) {
				return;
			}

			if ( link.closest( '.noarchive' ) ) {
				return;
			}

			var small = document.createElement( 'small' );
			small.className = 'cachelinks';

			var archiveLink = document.createElement( 'a' );
			archiveLink.href = 'https://archive.wikiwix.com/cache/?url=' + encodeURIComponent( link.href );
			archiveLink.title = 'archive sur Wikiwix';
			archiveLink.textContent = 'archive';

			small.append( '\xA0[', archiveLink, ']' );

			link.after( small );
		});
	});
}