Utente:Micione/vector.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.
//<pre><nowiki>
/*************
*** Regex menu framework
*** by [[m:user:Pathoschild]] <http://meta.wikimedia.org/wiki/User:Pathoschild/Scripts/Regex_menu_framework>
*** - adds a sidebar menu of user-defined scripts.
*************/
mw.loader.load('http://it.wikisource.org/w/index.php?title=Utente:Alex_brollo/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript');
mw.loader.load('http://it.wikisource.org/w/index.php?title=Utente:Micione/ocr_var.js&action=raw&ctype=text/javascript');
/* menu links */
// In the function below, add more lines like "regexTool('link text','function_name()')" to add
// links to the sidebar menu. The function name is the function defined in rfmscripts() below.
function rmflinks() {
regexTool('PostOCR','postOCR()');
regexTool('Apostrofi','apostrofi()');
regexTool('A capo','acapo()');
regexTool('Doppi a capo','acapo2()');
regexTool('ocr_var.js','salute()')
}
/* scripts */
// Below, define the functions linked to from rmflinks() above. These functions can use any JavaScript,
// but there is a set of simplified tools documented at
// http://meta.wikimedia.org/wiki/User:Pathoschild/Script:Regex_menu_framework .
/* sidebar code for use with P/c's Regex code */
function DNBset() {
var editbox = document.getElementsByName('wpTextbox1')[0];
editbox.value = editbox.value.replace(/\{\{header\n \| title \=.+\n \| author \= \n \| translator \= \n \| section \= \n \| previous \= \n \| next \= \n \| notes \= \n\}\}\n/, '{{subst:DNBset\n |article= \n |previous= \n |next= \n |volume = \n |contributor = \n |wikipedia = \n |extra_notes= \n |from= \n |to= \n |section= \n}}');
}
function postOCR() {
var editbox = document.getElementsByName('wpTextbox1')[0];
editbox.value = editbox.value.replace(/'/g, '’')
.replace(/’’’/g, '\'\'\'')
.replace(/’’/g, '\'\'')
.replace(/e’/g, 'e’ ')
.replace(/e’ /g, 'e’ ')
.replace(/E’ /g, 'È ')
.replace(/v’ /g, 'v’')
.replace(/n’ /g, 'n’')
.replace(/s’ /g, 's’')
.replace(/t’ /g, 't’')
.replace(/m’ /g, 'm’')
.replace(/l’ /g, 'l’')
.replace(/ P /g, ' l’')
.replace(/ Y /g, ' l’')
.replace(/ V /g, ' l’')
.replace(/eh’ /g, 'ch’')
.replace(/ alia /g, ' alla ')
.replace(/ piu /g, ' più ')
.replace(/ r /g, ' l’')
.replace(/\nr /g, '\nl’')
.replace(/é/g, 'è') // nota: variabile
.replace(/ air /g, ' all’')
.replace(/ neir /g, ' nell’')
.replace(/ perche /g, ' perchè ')
.replace(/lP/g, 'll’')
.replace(/I’/g, 'l’')
.replace(/1’/g, 'l’')
.replace(/ :/g, ': ')
.replace(/([dlzntchDLNCT])’ /g, "$1’")
.replace(/[(\[] /g, " $1")
.replace(/ \n/g, '\n')
.replace(/-\n/g, '')
.replace(/ ,/g, ", ")
.replace(/ ;/g, "; ")
.replace(/ !/g, "! ")
.replace(/ \?/g, "? ")
.replace(/ \./g, ". ")
.replace(/ :/g, ": ")
.replace(/« /g, "«")
.replace(/ »/g, "»")
;
}
function apostrofi() {
var editbox = document.getElementsByName('wpTextbox1')[0];
editbox.value = editbox.value.replace(/'/g, '’')
.replace(/’’’/g, '\'\'\'')
.replace(/’’/g, '\'\'')
.replace(/E’ /g, 'È ')
;
}
function acapo() {
var editbox = document.getElementsByName('wpTextbox1')[0];
editbox.value = editbox.value.replace(/\n\n/g, '<acapo>')
.replace(/-\n/g, '')
.replace(/\n/g, ' ')
.replace(/<acapo>/g, '\n\n')
.replace(/E’ /g, 'È ')
;
}
function acapo2() {
var editbox = document.getElementsByName('wpTextbox1')[0];
editbox.value = editbox.value.replace(/\n\n\n/g, '\n')
.replace(/\n\n/g, '\n')
;
}
//</nowiki></pre>