Utente:FreeCorp/LongSRestore.js
Notarella: Aroppo pubbreca putisse necessità 'e pulezzà 'a caché d' 'o navigatóre pe vedé 'e cagnamienti.
- Firefox / Safari: Sprémme 'o buttóne maiuscole e ffà clic ncopp'a Recarreca, o pure spremme Ctrl-F5 o Ctrl-R (⌘-R ncopp'a Mac)
- Google Chrome: spremme Ctrl-Shift-R (⌘-Shift-R ncopp'a nu Mac)
- Internet Explorer/edge: Spremme 'o buttóne Ctrl pe' tramente ca faie click ncopp'a Refresh, o pure spremmere Ctrl-F5
- Opera: Vaje addò 'o Menu → Mpustaziune (Opera → Mpustaziune ncopp' 'o Mac) e po' ncopp'a Privacy & sicurezza → Pulezza date d' 'o browser → Immaggene e file d' 'a cache.
/*jshint boss:true*/
/*global $, mw*/
/*
Derived from script from https://nap.wikisource.org/wiki/Utente:Alex_brollo/GoogleOCR.js
To use it: https://nap.wikisource.org/w/index.php?title=User:FreeCorp/LongSRestore.js&action=raw&ctype=text/javascript
*/
/**
* 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();
// Replace - in the beginning of a line by — (for dialogues)
text = text.replace(/([^{])s([^ \-’.,f…\n])/g, '$1ſ$2');
text = text.replace(/([^{])s([^ \-’.,f…\n])/g, '$1ſ$2');
text = text.replace(/{{perſonnage/g, '{{personnage');
text = text.replace(/{{acteurſ/g, '{{acteurs');
text = text.replace(/{{didaſcalie/g, '{{didascalie');
text = text.replace(/ligneſ=/g, 'lignes=');
text = text.replace(/ſuffix=/g, 'suffix=');
$( '#wpTextbox1' ).val( text );
}
run();
}( mediaWiki, jQuery ) );