Utilizador:Nonexyst/common.js
Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Internet Explorer / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
- Opera: Pressione Ctrl-F5.
function ocr_1() {
var textArea = $('#wpTextbox1');
var txt = textArea.textSelection('getSelection');
if (txt === '') {
txt = textArea.textSelection('getContents');
txt = ocr_1_inner(txt, 1);
textArea.textSelection('setContents', txt);
} else {
txt = ocr_1_inner(txt, 0);
textArea.textSelection('encapsulateSelection', {pre: txt, replace: true});
}
}
function ocr_1_inner(sel, r) {
// manipulate the text in the sel variable
sel = sel.replace(/[ \t]+$/gm, ''); // remove trailing spaces
sel = sel.replace(/^[ \t]+/gm, ''); // remove leading spaces
sel = sel.replace(/[ \t]+/gm, ' '); // remove multiple spaces
sel = sel.replace(/(\S)[\-¬]\n(\S)/gm, '$1$2'); // merge lines in the paragraph separated with dash into single line
sel = sel.replace(/(\S)\n(\S)/gm, '$1 $2'); // merge other lines in the paragraph into single line
if (r) { // remove leading and trailing line feeds
sel = sel.replace(/\n/gm, '\x01'); // hide \n's
sel = sel.replace(/^\x01+/gm, ''); // remove leading line feeds
sel = sel.replace(/\x01+$/gm, ''); // remove trailing line feeds
sel = sel.replace(/\x01/gm, '\n'); // restore hidden \n's
}
return sel;
}
function ocr_2() {
var textArea = $('#wpTextbox1');
txt = textArea.textSelection('getContents');
txt = ocr_2_inner(txt);
textArea.textSelection('setContents', txt);
}
function ocr_2_inner(sel) {
// manipulate the text in the sel variable
sel = sel.replace(/\n/gm, '\x01'); // hide \n's
sel = sel.replace(/^(\x01*)([\-a-zA-Z0-9А-Яа-яёЁІіѢѣѲѳѴѵ]+)/gm, '$1{{tiret2|…|$2}}'); //
sel = sel.replace(/\x01/gm, '\n'); // restore hidden \n's
return sel;
}
function ocr_3() {
var textArea = $('#wpTextbox1');
txt = textArea.textSelection('getContents');
txt = ocr_3_inner(txt);
textArea.textSelection('setContents', txt);
}
function ocr_3_inner(sel) {
// manipulate the text in the sel variable
sel = sel.replace(/\n/gm, '\x01'); // hide \n's
sel = sel.replace(/([\-a-zA-Z0-9А-Яа-яёЁІіѢѣѲѳѴѵ]*[a-zA-Z0-9А-Яа-яёЁІіѢѣѲѳѴѵ])[-¬]?(\x01*)$/gm, '{{tiret|$1|…}}$2'); //
sel = sel.replace(/\x01/gm, '\n'); // restore hidden \n's
return sel;
}
function ancres()
{
var textArea = $('#wpTextbox1');
txt = textArea.textSelection('getContents');
txt = txt.replace(/^'''([^\.\,\']+)([\.\,]{0,1})\s{0,}'''/gm, "'''{{ancre|$1|$1}}$2'''");
textArea.textSelection('setContents', txt);
}
jQuery( document ).ready( function( $ ) {
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
mw.loader.using( 'ext.wikiEditor', function () {
////////////////////////////////////////////////////
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
/// 'section': 'advanced',
'section': 'proofreadpage-tools',
'groups': {
'OCR': {
'label': 'Instruments supplémentaires:'
}
}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
/// 'section': 'advanced',
'section': 'proofreadpage-tools',
'group': 'OCR',
'tools': {
'OCR-1': {
//label: '',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/8/8b/Merge-arrows.gif',
action: {
type: 'callback',
execute: function(context){
ocr_1();
}
}
},
'OCR-2': {
//label: '',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/6/68/Merge-arrow.gif',
action: {
type: 'callback',
execute: function(context){
ocr_3();
}
}
},
'OCR-3': {
//label: '',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/a/ae/Mergefrom.gif',
action: {
type: 'callback',
execute: function(context){
ocr_2();
}
}
},
'ancres': {
//label: '',
type: 'button',
icon: 'https://upload.wikimedia.org/wikipedia/commons/4/44/BluewaterTrail.png',
action: {
type: 'callback',
execute: function(context){
ancres();
}
}
}
}
} );
////////////////////////////////////////////////////
} );
}
} );