Aller au contenu

Utilisateur:Musstruss/vector-2022.js

Une page de Wikiquote, le recueil des citations libres.

Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

  • Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
  • Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
  •  Edge : 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}}
 */

{
	mw.hook( 'wikipage.content' ).add( function ( $content ) {
		'use strict';

		var hasNativeClosest = !!Element.prototype.closest;

		$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 ( hasNativeClosest ) {
				if ( link.closest( '.noarchive' ) ) {
					return;
				}
			} else {
				if ( $( link ).closest( '.noarchive' ).length ) {
					return;
				}
			}

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

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

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

			link.insertAdjacentHTML( 'afterend', '<small class="cachelinks">\xA0[' + archiveLink + ']</small>' );
		});
	});
}