MediaWiki:Gadget-postOCRautomatico.js
Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.
- Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
- Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
- Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
- Opera: premi Ctrl-F5.
function dehyphen() {
scriviBox(leggiBox().replace(/([^|])[-¬] *\n([^ \n]*)[ ]*[\n]?/g,"$1$2\n"));
}
/* function dehyphen(testo) {
while (true) {
pos = testo.indexOf("-\n");
if (pos == -1) break;
testo = testo.replace("-\n", "");
for (i = pos; i < testo.length; i += 1) {
if (testo.substring(i, i + 1) == " ") {
testo = testo.substring(0, i) + "\n" + testo.substring(i + 1);
break;
}
}
}
return testo;
} */
if (mw.config.get('wgCanonicalNamespace') === 'Page' && mw.config.get('wgAction') === 'edit' && mw.config.get('wgArticleId') === 0) {
$('#wpTextbox1').ready(function () {
var editbox = document.getElementsByName('wpTextbox1')[0];
editbox.value = editbox.value.replace(/'/g, '’').replace(/’’’/g, '\'\'\'').replace(/’’/g, '\'\'').replace(/ \n/g, '\n');
// tento di disabilitare la riunione delle righe spezzate
//.replace(/-\n/g, '')
//.replace(/- \n/g, '');
dehyphen(); // eseguo temporaneamente dehyphen in attesa di costruire/trovare la regex giusta
editbox.value = editbox.value.replace(/ì’/g, 'l’')
.replace(/1’/g, 'l’')
.replace(/ deir /g, ' dell’')
.replace(/ air /g, ' all’')
.replace(/ neir /g, ' nell’')
.replace(/ perche /g, ' perchè ')
.replace(/ poiche /g, ' poichè ')
.replace(/ piu /g, ' più ')
.replace(/\s+([,;.:!?])/g, '$1')
.replace(/«\s+/g, '«')
.replace(/\s+»/g, '»')
.replace(/([bcdfghlmnprstvzBCDFGHLMNPRSTV])’\s+/g, '$1’')
.replace(/eh’/g, 'ch’')
.replace(/\s+$/, '');
});
$('#wpFooterTextbox').ready(function () {
//inserisce un a capo all'inizio del footer (per il bug 26028)
footer = $('[name=wpFooterTextbox]');
if (footer.length > 0 && !footer.val().match(/^\n/)) {
footer.val('\n' + footer.val());
}
});
}