Utente:Samuele Papa/vector.js

Da Wikisource.

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.
// <nowiki>
importScript("Utente:Alex brollo/hOCR.js");
//noteBibbia
//Put each note in each line. If note has more refs then put all of them in the same line
//(\d+) (\w+) (\d+)\.\W+(\d+)
/**
 * ROUTINE
 * Una routine permetted di concatenare più operazioni che vengono 
 * automaticamente eseguite quando si preme un pulsante
 * 
 * TODO:
 * 	- definire un elenco di azioni possibili
 * 	- decidere quanta customizzazione è lasciata
 * */
/*class IDkeeper{
	static newID()
}
class RoutineManager{
	constructor(){
		this.list = {}
	}
	add(routine){
		this.list[this.routine.name] = routine
	}
}
class ActionManager{
	constructor(){
		list = {}
	}
	add(routine){
		this.list[this.routine.name] = routine
	}
	static getter(name){
		return this.list[this.routine.name]
	}
}
class action{
	constructor(name, fun){
		this.name = name;
		
	}
}
class routine{
	constructor(name){
		this.name = name;
		this.ID = name;
		this.list = []
	}
	addAction(name){
		this.list[this.list.length] = routine
	}
	start(){
		for(var a in list){
			list[a].call(this)
		}
	}
}
*/
var noteBibbia=(function(){
	var pubblic={};
	var text="";
	pubblic.setText=function(){
		var editbox = document.getElementsByName('wpTextbox1')[0];
        text=editbox.value;
	}
	pubblic.cleanup=function(){
		var reg="/<!-- note -->\s*\n+(.+\n*)+/g";
		text=text.match(reg);
		text=text.replace(reg,"$1");
		console.log(text);
	};
	return pubblic;
}());
//importScript("Utente:Alex brollo/parseTemplate.js");
importScript("Utente:Alex brollo/getPage.js");

function accenta_ultima(){
    t=selection()[0]+selection()[1];
    myarr=selection()[2].split('')
    i=0
    while(myarr[i]){
    if(myarr[i]==' '){
    console.log('Last character:'+myarr[i-1])
    myarr[i-1]='ò'
    break;
    }
    i++
    }
    t=t+myarr.join('')
}
 
/*if (wgCanonicalNamespace=="Pagina"){
mw.loader.load('//it.wikisource.org/w/index.php?title=Utente:Samuele_Papa/editorline.js&action=raw&ctype=text/javascript');
}*/


function addreftoBiblink(testo) {
testo=testo.replace(/[^>](\{\{BibLink)([^{]+?)(\}\})([,;-])/g,'<ref>{' + '{BibLink$2}}$4');
testo=testo.replace(/([;,-])(\{\{BibLink)([^{]+?)(\}\})[^,;-]/g,'$1{' + '{BibLink$3}}</ref>');
 
testo=testo.replace( /[^>](\{\{BibLink)([^{]+?)(\}\})[^<]/g,'<ref>{' + '{BibLink$2}}</ref>');
$('#wpTextbox1').val(testo);
}

function cioe2accento(){
      var editbox = document.getElementsByName('wpTextbox1')[0];
       testo=editbox.value;

testo=testo.replace('cioe','cioè');
$('#wpTextbox1').val(testo);
}
/* mybibbia2() trasforma 2 Cor. 11, 7, ecc. o cose simili in {{BibLink|2 Cor|11|7}}ecc. 
Ho deciso di far funzionare lo script solo con quello selezionato */
function mybibbia2(){
       testo=Selection();
       var pattern=/([0-9][ ]|[]|[0-9][0-9][ ])([A-Za-z]+)(\W+)([0-9]+)([\W]+)([0-9]+)([\W]+)/;
       testo=testo.replace(pattern,"{{BibLink|$1$2|$4|$6}}")
       return testo;
}
/* Prova a sostituire note con più versetti una dietro l'altro, separati da una virgola*/
function bibbia4(){
      var editbox = document.getElementsByName('wpTextbox1')[0];
      testo=editbox.value;
      /* Pattern per sistemare le funzioni primordiali deve partire prima di tutti */
      testo=testo.replace(/[^{{\w\|\(]([1-3] [a-zA-Z]+)\s*\W*([^\/][0-9]+)\.\s*\W*([0-9]+)/g,'{{BibLink|$1|$2|$3}}');
      testo=testo.replace(/[^{{\w\|\(]([a-zA-Z]+)\s*\W*([^\/][0-9]+)\.\s*\W*([0-9]+)/g,'{{BibLink|$1|$2|$3}}');
      /*Trova i versetti aggiuntivi*/
      var patt=/(\{\{BibLink[^\{\{]+?[0-9]+\|)([0-9]+\}\})[,][\W]+([0-9]+)[,][\W]+([0-9]+)[,][\W]+([0-9]+)/g;
      testo=testo.replace(patt,"$1$2,$1$3|$3}},$1$4|$4}},$1$5|$5}}");
      var patt=/(\{\{BibLink[^\{\{]+?[0-9]+\|)([0-9]+\}\})[,][\W]+([0-9]+)[,][\W]+([0-9]+)/g;
      testo=testo.replace(patt,"$1$2,$1$3|$3}},$1$4|$4}}");
      var patt=/(\{\{BibLink[^\{\{]+?[0-9]+\|)([0-9]+\}\})[,][\W]+([0-9]+)/g;
      testo=testo.replace(patt,"$1$2,$1$3|$3}}");
      var patt=/(\{\{BibLink[^\{\{]+?[0-9]+\|)([0-9]+\}\})[,-]+([0-9]+)/g;
      testo=testo.replace(patt,"$1$2-$1$3|$3}}");
      var patt=/([123]\s)({{BibLink\|)/g;
      testo=testo.replace(patt,'$2$1');
      var patt=/(\{\{BibLink[^\{\{]+?)([0-9]+\|)([0-9]+\}\})[;][\W]+([0-9]+)[.][\W]+([0-9]+)/g;
      testo=testo.replace(patt,'$1$2$3;$1$4|$5|$4.$5}}');
      addreftoBiblink(testo)
}
//This still needs work
function refInBible(){
var editbox = document.getElementsByName('wpTextbox1')[0];
testo=originaltext=editbox.value;
//Isola le note
testo=testo.match(/<!-- note -->((.*\n*)*)<!-- fine note -->/g)[0]
testo=testo.replace(/<!-- note -->((.*\n*)*)<!-- fine note -->/g,'$1');
//Ottieni tutte le reference, una per riga
var arrRef=testo.match(/(.+)\n*/g);
//Cicla tutte le reference trovate
var fullNote='';
for(var a in arrRef){
  //Now magic will happen, don't ask...
  var Blink,currRef
  currRef=arrRef[a]
  
  if(currRef.length>1){
    Blink='<ref>';
    currRef=currRef.replace(/\n+/g,'');
    if(currRef[0]=='{'){
      Blink+=currRef+'</ref>\n';
    }else{
      var BlinkLine='{{BibLink|';
      var elementadded=0;
      currRef=currRef.match(/\S+/g);
      var type='';b
      var separation='';
      for(var b in currRef){
        
        if(currRef[b].match(/[\\.\\-\\,\\;]/g)&&currRef[b].match(/[0-9]/g)){
          if(currRef[b].match(/\./g)){
            console.log(type)
            if(type=='versetto'){
              BlinkLine+='}}'+separation+' '+versettotemp+'|'+currRef[b].match(/[0-9]*/g)[0]+'|'+currRef[b].match(/[0-9]*/g)[0]+'}}';
            }else if(type=='capitolo'){
              BlinkLine+='}}'+separation+' '+capitolotemp+'|'+currRef[b].match(/[0-9]*/g)[0]+'|'+currRef[b].match(/[0-9]*/g)[0]+'}}';
            }else if(type=='continua'){
              BlinkLine+='|'+currRef[b].match(/[0-9]*/g)[0]+'}}';
              type='stop';
            }else{
              type='continua';
              BlinkLine+='|'+currRef[b].match(/[0-9]*/g)[0];
              var versettotemp=BlinkLine;
            }
          }else if(currRef[b].match(/[\\,\\-]/g)){
            separation=currRef[b].match(/[\\,\\-]/g)[0];
            if(type=='versetto'){
               BlinkLine+='}}'+separation+' '+versettotemp+'|'+currRef[b].match(/[0-9]*/g)[0]+'|'+currRef[b].match(/[0-9]*/g)[0];
            }else{
              type='versetto'
              BlinkLine+='|'+currRef[b].match(/[0-9]*/g)[0];
            }
          }else if(currRef[b].match(/;/g)){
            separation=currRef[b].match(/;/g)[0];
            if(type=='capitolo'){
              BlinkLine+='}}'+separation+' '+capitolotemp+'|'+currRef[b].match(/[0-9]*/g)[0]+'|'+currRef[b].match(/[0-9]*/g)[0];
            }else{
              type='capitolo';
              BlinkLine+='|'+currRef[b].match(/[0-9]*/g)[0];
            }
          }
        }else{
          //if it's the number or the text at the beginning, add it with or without a space
          if(elementadded==1)
            BlinkLine+=' ';
          BlinkLine+=currRef[b];elementadded++;
          var capitolotemp=BlinkLine;
        }
        
      }
      Blink+=BlinkLine+'</ref>\n';
    }
  }
  fullNote+=Blink
}
originaltext=originaltext.replace(/<!-- note -->((.*\n*)*)<!-- fine note -->/g,fullNote);
$('#wpTextbox1').val(originaltext);
}
function hegelNewline(){
	var editbox = document.getElementsByName('wpTextbox1')[0];
	testo=editbox.value;
	testo=testo.replace(/\n/g,'');
	$('#wpTextbox1').val(testo);
}
/*
function findchapter(n,from,to){
z=0
found=[]
for(i=from;i<=to;i++){
testo=acchiappaWikicode('Pagina:La_Sacra_Bibbia_(Diodati_1885).djvu/'+i);
arraymatched=testo[1].match(/section \D+(\d+)/g);
arraymatched2=[]
for(e=0;e<=arraymatched.length-1;e++){
arraymatched2[e]=arraymatched[e].replace(/section end\D/,'')
 }
if(arraymatched2.indexOf(''+n+'')!=-1){
found[z]=i
z=z+1
}
}
return '<pages index="La Sacra Bibbia (Diodati 1885).djvu" from='+found[0]+' to='+found[z-1]+' fromsection='+n+' tosection='+n+' />';
}

function setpageBibbia(cap,from,to){
testo='{{Qualità|avz=75%|data=26 febbraio 2012|arg=Da definire}}{{IncludiIntestazione|sottotitolo=|prec=../capitolo_'+(cap-1)+'|succ=../capitolo_'+(parseInt(cap)+1)+'}}'
testo+='\n'
testo+=findchapter(cap,from,to)
testo+='\n'
testo+='{{Sezione note}}'

scriviBox(testo)
$('#bibbiatransbox').find('*').each(function(){
 $(this).remove()
}).remove();
$('#bibbiatransbox').remove();
}
function BibbiaTrasBox(){
$('body').append('<div id="bibbiatransbox"></div>');
$('#bibbiatransbox').append('<label for="from">From:</label>');
$('#bibbiatransbox').append('<input type="text" id="from" />');
$('#bibbiatransbox').append('<br><label for="to">To:</label>');
$('#bibbiatransbox').append('<input type="text" id="to" />');
$('#bibbiatransbox').append('<br><label for="cap">Capitolo:</label>');
$('#bibbiatransbox').append('<input type="text" id="cap" />');
$('#bibbiatransbox').append('<input type="submit" id="bibbiaboxsub" value="Trova e fai" />');
$('#bibbiatransbox').dialog();
$('#bibbiaboxsub').on('click',function(){
setpageBibbia($('#bibbiatransbox').children('#cap').val(),$('#bibbiatransbox').children('#from').val(),$('#bibbiatransbox').children('#to').val());
});
}
*/
// </nowiki>