Note : après avoir enregistré 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 pressez Ctrl-F5 ou Ctrl-R (⌘-R sur un Mac) ;
  • Google Chrome : Appuyez sur Ctrl-Maj-R (⌘-Shift-R sur un Mac) ;
  • Internet Explorer : Maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ;
  • Opera : Allez dans Menu → Settings (Opera → Préférences sur un Mac) et ensuite à Confidentialité & sécurité → Effacer les données d'exploration → Images et fichiers en cache.
/*
Dérivé de https://nap.wikisource.org/w/index.php?title=Utente:FreeCorp/LongSRestore.js
lui-même dérivé de https://nap.wikisource.org/wiki/Utente:Alex_brollo/GoogleOCR.js
*/

/**
 * This script adds a toolbar button which replaces s by ſ when it is relevant
 */

( function ( mw, $ ) {
	var lang = mw.config.get( 'wgContentLanguage' );
	// Questo if ridefinisce lang in "it" per le tre wikisource italiane minori
	if (["nap","vec","pms"].indexOf(lang)!==-1) {
    	lang="it";
	}
	var toolUrl = "//tools.wmflabs.org/ws-google-ocr/api.php";
	var loadingGifUrl = '//upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif';
	var sysMessages = [ 'google-ocr-button-label', 'google-ocr-request-in-progress', 'google-ocr-no-text', 'google-ocr-image-not-found' ];

	/**
	 * The initialisation function, run on every load. Adds the button to the
	 * toolbar if we're currently editing or previewing in the Page namespace.
	 */
	function run() {
		var isPage, useOldToolbar, useBetaToolbar, toolbarLib;
		mw.loader.using( 'user.options', function () {
			isPage = mw.config.get( 'wgCanonicalNamespace' ) === 'Page';
			useOldToolbar = mw.user.options.get( 'showtoolbar' ) === 1;
			useBetaToolbar = mw.user.options.get( 'usebetatoolbar' ) === 1;
			if ( isPage && ( useOldToolbar || useBetaToolbar ) ) {
				toolbarLib = useBetaToolbar ? 'ext.wikiEditor' : 'mediawiki.toolbar';
				mw.loader.using( [ 'mediawiki.api', toolbarLib ], function () {
					new mw.Api().loadMessagesIfMissing( sysMessages ).then( function() { customizeToolbar( useBetaToolbar ); } );
				} );
			}
		} );
	}

	/**
 * This script adds a toolbar button which replaces s by ſ when it is relevant
	 *
	 * @param {boolean} useBeta Whether the WikiEditor toolbar should be used.
	 */
	function customizeToolbar( useBeta ) {

		// Add old-style toolbar button.
		if ( ! useBeta && mw.toolbar ) {
			mw.toolbar.addButton( {
				imageFile: 'https://upload.wikimedia.org/wikipedia/commons/1/13/Button_API_%CA%83.png',
				speedTip: mw.msg( 'long-s-restore-button-label' ),
				imageId: 'LongSRestoreButton'
			} );
			$("img#LongSRestoreButton").on('click', longSRestore).css("width", "50px");
		}

		// Add new-style WikiEditor toolbar button.
		if ( useBeta ) {
			$( document ).ready( function () {
				var ocrButtonDetails = {
					type: 'button',
					icon: 'https://upload.wikimedia.org/wikipedia/commons/1/13/Button_API_%CA%83.png',
					labelMsg: 'long-s-restore-button-label',
					action: { type: 'callback', execute: longSRestore }
				};
				var longSRestoreButton = {
					section: 'main', // 'proofreadpage-tools',
					group: 'insert', // 'other',
					tools: { 'LongSRestore': ocrButtonDetails }
				};
				$( "#wpTextbox1" ).wikiEditor( 'addToToolbar', longSRestoreButton );
				$( "a[rel='LongSRestore']" ).css("width", "42px");
			} );
		}

		// Pre-load the loading gif.
		$( '<img />' ).attr( 'src', loadingGifUrl ).appendTo( 'body' ).hide();
	}

	/**
	 * This function is run when the long S restore button is clicked.
	 * It replaces any round s by a long s when it is relevant
	 */
	function longSRestore() {
		var text = $( '#wpTextbox1' ).val();
        /* Application de https://www.rexegg.com/regex-best-trick.html */
        /* On met les cas exclus (1° modèles, 2° tableau,
           3° avant un f, 4° à la fin d’un mot) avant le dernier pipe. */
        /* Pour des tests :  
           "s sos sosses soses sçay osées, les. les? les-rèsès les:les les " */
        var regex = /\{\{[^}]+\}\}|\{\|[^\}]+|sf|s[\p{M}\p{P}\p{S}\p{Z}]|(s)/gu;
        var group1Caps = [];
        var match = regex.exec(text);
        while (match != null) {
	        if(match[1] != null) 
	            group1Caps.push(match[1]);
            match = regex.exec(text);
        }
        text = text.replace(regex, function(m, group1) {
            if (group1 === undefined ) 
                return m;
            else 
                return "ſ";
        });
        
        text = text.replace(/ u/g," v");
        text = text.replace(/’u/g,"’v");
        text = text.replace(/\(u/g,"(v");
        text = text.replace(/([a-zA-Z])v([a-zA-Z])/g,"$1u$2");
        text = text.replace(/j/g,"i");
        text = text.replace(/J/g,"I");

		$( '#wpTextbox1' ).val( text );
	}

	run();
}( mediaWiki, jQuery ) );