User:Alex brollo/libreriaVector.js
Jump to navigation
Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Clear the cache in Tools → Preferences
For details and instructions about other browsers, see Wikipedia:Bypass your cache.
Code that you insert on this page could contain malicious content capable of compromising your account. If you are unsure whether code you are adding to this page is safe, you can ask at the central discussion page, Scriptorium. The code will be executed when previewing this page under some skins, including Monobook. You can in the interim if you wish to refresh the content sooner under another skin. |
Documentation for this script can be added at User:Alex brollo/libreriaVector. |
//<source lang="javascript">
/* importScript("Utente:Alex brollo/parseTemplate.js");
importScript("Utente:Alex brollo/getPage.js");
importScript("Utente:Alex brollo/Tabella_attiva.js");*/
function readMyCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); }
return null;}
mw.loader.load('//commons.wikimedia.org/w/index.php?title=MediaWiki:JSValidator.js&action=raw&ctype=text/javascript');
mw.loader.load('//it.wikisource.org/w/index.php?title=Utente:Alex_brollo/pagelistParsing.js&action=raw&ctype=text/javascript');
mw.loader.load('//it.wikisource.org/w/index.php?title=Utente:Alex_brollo/zs.js&action=raw&ctype=text/javascript');
$("#content").append($('<div id="newtattoo" align="right" style="position:fixed;bottom:0; right:0; background-color:white; border: 1px solid; border-color:#F0F0F0; z-index:1500;"></div>'));
/* funzione spostata in Utente:Alex brollo/getPage.js
function getIwPage (title, site, query, callback) {
if (query == undefined) query = "text";
if (query == "html" || query == undefined) data = {
format: 'json',
action: 'parse',
page: title,
prop: 'text'
};
if (query == "text") data = {
format: 'json',
action: 'query',
titles: title,
prop: 'revisions',
rvlimit: '1',
rvprop: 'content'
};
$.ajax({
url: 'https://' + site + '/w/api.php',
async: false,
data: data,
dataType: 'jsonp' // this is the important one!
}).done(function (data) {
$("body").data("outputAjax", data);
if (query === "text") {
if (data.query.pages[-1] == undefined) {
l = [];
for (var i in data.query.pages) {
l.push(i);
};
bareData = data.query.pages[l[0]].revisions[0]["*"];
} else {
bareData = "Pagina non esistente";
}
if (query === "html") {
if (data.error == undefined) {
bareData = data.parse.text["*"];
} else {bareData = "Pagina non esistente";}
}
}
$("body").data("bareData", bareData);
if (callback !== undefined) {
callback();
}
});
} */
newButton("//upload.wikimedia.org/wikipedia/commons/5/5f/Button_center.png", "incapsula('{{Center|','}}')", "es");
newButton("//upload.wikimedia.org/wikipedia/commons/a/a2/SmallcapsButton.png", "incapsula('{{Sc|','}}')", "es");
newButton("//upload.wikimedia.org/wikipedia/commons/2/2a/Button_Subheadline.gif", "incapsula('{{Rule|4em}}','')", "es");
newButton("//upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Button_capitalize.svg/23px-Button_capitalize.svg.png", "capit()", "es");
newButton("//upload.wikimedia.org/wikipedia/commons/thumb/0/0c/Button_Up_Low_toggle.svg/23px-Button_Up_Low_toggle.svg.png", "up_low()", "es");
newButton("//upload.wikimedia.org/wikipedia/commons/2/25/Btn_toolbar_indent_more.png", "indentSelection()", "es");
newButton("//upload.wikimedia.org/wikipedia/commons/a/ab/Btn_toolbar_indent_less.png", "deIndentSelection()", "es");
newButton("//upload.wikimedia.org/wikipedia/commons/5/56/Center.png", "eliminaRigheVuote()", "es");
//newButton("show", "show('wiki text')", "evs");
//newButton("metadati", "show(1)", "es");
//newButton("NewPP", "NewPP", "v");
newButton("note", "note", "es");
// newButton("autoRi", "newRi", "es");
//newButton("autoPt", "autoPt", "es");
// newButton("autoNs0", "ns0Auto", "es");
// newButton("autoSomm", "autoSommario", "es");
// newButton("autoInd", "autoIndice", "es");
newButton("sections", "incapsula('<section begin= />','<section end= />')", "es");
newButton("preOCR", "preOCR()", "es");
newButton("tableM", "tableMaker()", "es");
importScript("User:"+wgUserName+"/PersonalButtons.js");
//newButton("ThPurge", "ThPurge()");
function find_stringa(testo,idi,idf,dc,x){idip=testo.indexOf(idi);idfp=testo.indexOf(idf,idip+idi.length)+idf.length;if(idip>-1&&idfp>-1){if(x!=""){while(count(testo.slice(idip,
idfp),x)>count(testo.slice(idip,idfp),idf)){idfp=testo.indexOf(idf,idfp)+idf.length;}}if(dc==0){vvalore=testo.slice(idip+idi.length,idfp-idf.length);}else{vvalore=testo.slice(idip,idfp);}}else{vvalore="";}return vvalore;}
function produciLista(testo,s1,s2,delim,x){lista=new Array();while(find_stringa(testo,s1,s2,true,x)>""){elemento=find_stringa(testo,s1,s2,true,x);testo=testo.replace(elemento,"");if(delim){lista.push(elemento);}else{lista.push(elemento.slice(s1.length,-s2.length));}}return lista;}
function scriviBox(testo,area,ss,se){if(area===undefined||area===""){if(wgCanonicalNamespace=="Page"){area=1;}else{area=0;}}$('textarea')[area].value=testo;console.log("area:",area);if(ss!=undefined&&se!=undefined){$('textarea')[area].selectionStart=ss;$('textarea')[area].selectionEnd=se;}}
function leggiBox(area){if(area==undefined){if(wgCanonicalNamespace=="Page")area=1;else area=0;}return $('textarea')[area].value;}
function apostrofi(editbox){if(editbox==undefined){var editbox=document.getElementsByName('wpTextbox1')[0];}var testoCod=codifica(editbox.value);testoCod[0]=testoCod[0].replace(/'/g,'’').replace(/’’’’’/g,"'''''").replace(/’’’’/g,"''''").replace(/’’’/g,"'''").replace(/’’/g,"''");editbox.value=decodifica(testoCod[0],testoCod[1]);}
function codifica(testo){var l=[];var res
=ss(testo,l,"<math","</math>","");res=ss(res[0],res[1],"<!--","-->","<");res=ss(res[0],res[1],"{","}","{");res=ss(res[0],res[1],"[","]","[");res=ss(res[0],res[1],"<",">","<");res=ss(res[0],res[1],"https://"," ","");res=ss(res[0],res[1],"https://"," ","");return res;}
function count(testo,stringa){n=0;while(testo.indexOf(stringa)>-1){n=n+1;testo=testo.replace(stringa,"");}return n;}
function decodifica(testo,l){for (var i=l.length-1;i>-1;i=i-1){testo=testo.replace("###el"+i+"###",l[i]);}return testo;}
function ss(testo,l,tagi,tagf,x){while(find_stringa(testo,tagi,tagf,1)>""){var el=find_stringa(testo,tagi,tagf,1,tagi);testo=testo.replace(el,"###el"+l.length+"###");l.push(el);}return[testo,l];}
function newButton(nome, funzione, azione, messaggio) { // azione è una stringa composta da v,e,s,h rispettivamente view,edit,submit,history
// fine se azione=history
if (wgAction === "history") {
return;
}
// normalizzazione function
if (funzione.indexOf("(") === -1 && funzione.indexOf(")") === -1) {
funzione += "()";
}
// default: bottone presente in view, edit,
if (azione === undefined) {
azione = "ves";
}
// messaggio di default
if (messaggio === undefined) {
messaggio = "Nessun messaggio di aiuto registrato";
}
// valutazione condizione di visualizzazione
if (wgAction === "edit" && azione.indexOf("e") === -1) {
return;
}
if (wgAction === "view" && azione.indexOf("v") === -1) {
return;
}
if (wgAction === "submit" && azione.indexOf("s") === -1) {
return;
}
// caso pulsante=immagine
if (nome.substring(0, 2) == "//") {
var html = '<img src="' + nome + '" onclick="' + funzione + '" title="' + messaggio + '"/>';
$("#newtattoo").append($(html));
}
// caso pulsante=label
else {
$("#newtattoo").append($('<button type="button" title="' + messaggio + '" onclick="' + funzione + '"><small>' + nome + '</small></button>'));
}
return false;
}
function selection(area){if(area==undefined){if(wgCanonicalNamespace=="Page")area=1;else area=0;}var txtarea=$('textarea')[area];var txt=$(txtarea).val();var s=[];s[0]=txt.substring(0,txtarea.selectionStart);s[1]=txt.substring(txtarea.selectionStart,txtarea.selectionEnd);s[2]=txt.substring(txtarea.selectionEnd);if(s[1].lastIndexOf(" ")==s[1].length-1){
s[1]=s[1].substring(0,s[1].length-1);s[2]=" "+s[2];}return s;}
function espandi() {
var lista = produciLista(leggiBox(), "(", ")", 1, "(");
for (var i = 0; i < lista.length; i += 1) {
if (newAbbr[lista[i]] !== undefined) {
scriviBox(leggiBox().replace(lista[i], newAbbr[lista[i]]));
}
}
}
function excludeR() {
t = selection();
t[1] = "::::::{{R-}}" + t[1];
scriviBox(t.join(""));
}
/*
function ptPostAuto() {
ptList=produciLista(testoPagPrec[1],"{{Pt|","}}",1,"{{");
if (ptList.length>0) {
mezzaparola=find_stringa(ptList[ptList.length-1],"{{Pt|","|",0).trim();
if (mezzaparola.substring(mezzaparola.length-1,mezzaparola.length)=="-") {
testocor=leggiBox();
primaMezzaparola=testocor.substring(0,testocor.indexOf(" "));
nPt="{{Pt|"+primaMezzaparola+"|"+mezzaparola.substring(0,mezzaparola.length-1)+primaMezzaparola+"}}";
testocor=testocor.replace(primaMezzaparola,nPt);
scriviBox(testocor);
}
}
ri=find_stringa(testoPagPrec[0],"{{RigaIntestazione","}}",0,"{{");
if (ri.length>0) {
ri="<!--"+ri+"-->";
header=ri+leggiBox(0);
scriviBox(header,0);
}
}
*/
/******** Fine funzioni di supporto a p2d() ************/
function elaboradatiPaginaTest(i) {
riga = datiPagina.righe[i][4];
// vediamo centrato
deltasin = datiPagina.righe[i][0] - datiPagina.paramPagina.min_x1;
deltadx = datiPagina.paramPagina.max_x2 - datiPagina.righe[i][2];
larghMax = datiPagina.paramPagina.max_x2 - datiPagina.paramPagina.min_x1;
larghRiga = datiPagina.righe[i][2] - datiPagina.righe[i][0];
if (larghRiga / larghMax < 0.95 && deltasin / deltadx > 0.7 && deltasin / deltadx < 1.4) riga = "{{Centrato|" + riga + "}}\n";
return riga + "\n";
}
function jsonView() {
myWindow = window.open('', '', 'width=500,height=200');
testo = 'datiPagine["' + base + '"]=' + JSON.stringify(datiPag) + ";";
myWindow.document.write(testo);
myWindow.focus();
}
function ns0(cap, pag) {
var editbox = document.getElementsByName('wpTextbox1')[0];
var testo = editbox.value;
ii = '{{IncludiIntestazione|sottotitolo=Capitolo #1|prec=../#0|succ=../#2}}\n\n<pages index="La Sacra Bibbia (Diodati 1885).djvu" from=#pag to=#pag1 fromsection=#1 tosection=#1 />\n\n{{Sezione note}}';
x = prompt("capitolo,pagina:").split(",");
cap = x[0];
pag = x[1];
testo = ii.replace(/\#1/g, cap).replace("#0", cap * 1 - 1).replace("#2", cap * 1 + 1).replace("#pag", pag).replace("#pag1", pag * 1 + 1);
editbox.value = testo;
}
function dts() {
var editbox = document.getElementsByName('wpTextbox1')[0];
var testo = editbox.value;
listaLemmi = produciLista(testo, "{{lemma|", "\n", 1);
for (var i = 0; i < listaLemmi.length; i += 1) {
if (listaLemmi[1].indexOf("@") === -1) {
lemma = find_stringa(listaLemmi[i], "{{lemma|", "}}, ", 1);
var lemmaVal = find_stringa(lemma, "{{lemma|", "}}, ", 0).toLocaleLowerCase();
lemmaDef = find_stringa(listaLemmi[i], lemma, "\n", 0);
section_b = "<section begin=@@ />".replace("@@", "@" + lemmaVal);
section_e = section_b.replace("<section begin", "<section end");
lemmaNew = lemma + section_b + lemmaDef + section_e + "\n";
testo = testo.replace(listaLemmi[i], lemmaNew);
}
editbox.value = testo;
}
}
// AltraColonna
function altraColonna() {
var t = selection();
if (t[1] !== "") {
alert("Il tool va lanciato senza selezionare alcun testo,\nma solo posizionando il cursore nel punto di inserimento di AltraColonna");
return;
}
t[0] = t[0].replace(/\{\{altracolonna\}\}/i, "");
t[2] = t[2].replace(/\{\{altracolonna\}\}/i, "");
// caso AltraColonna in riga vuota
if (t[0].charAt(t[0].length - 1) === "\n" && t[2].charAt(0) === "\n") {
scriviBox(t[0] + "{{AltraColonna}}" + t[2]);
return;
}
// caso AltraColonna a fine parola
if (t[2].charAt(0) === " ") {
t[0] += " ";
t[2] = t[2].substring(1);
}
if (t[0].charAt(t[0].length - 1) === " ") {
scriviBox(t[0] + "{{AltraColonna}}" + t[2]);
return;
}
// caso AltraColonna a metà parola
if (/[A-z]$/.test(t[0]) && /^[A-z]/.test(t[2])) {
inizioParola = t[0].lastIndexOf(" ") + 1;
inizioP = t[0].substring(inizioParola);
fineParola = t[2].indexOf(" ");
fineP = t[2].substring(0, fineParola);
t[0] = t[0].substring(0, inizioParola) + "{{Pt|#|}}".replace("#", inizioP + "-");
t[2] = "{{Pt|#|§}}".replace("#", fineP).replace("§", inizioP + fineP) + t[2].substring(fineParola);
scriviBox(t[0] + "{{AltraColonna}}" + t[2]);
return;
}
}
//
acd_add = {};
function ac_plus() {
var t = selection();
var autore = t[1];
if (acd[autore] === undefined) {
if (acd_add[autore] !== undefined) {
acd[autore] = acd_add[autore];
} else {
autoreCompleto = prompt("Autore ignoto. Inserisci cognome e nome:", autore);
autoreCompleto = autoreCompleto.trim();
if (autoreCompleto === "") return;
acd_add[autore] = autoreCompleto;
acd[autore] = autoreCompleto;
saveCookAcd();
}
}
t[1] = "{{AutoreCitato|" + acd[autore] + "|" + autore + "}}";
scriviBox(t.join(""));
}
// Funzioni specifiche per i cookies; gestione cookie Acd, oggetto acd_add (autori aggiuntivi)
function saveCookAcd() {
datiAcd = escape(JSON.stringify(acd_add));
createMyCookie("Acd", datiAcd, 60);
}
function readCookAcd() {
if (readMyCookie("Acd") !== null) {
acd_add = JSON.parse(unescape(readMyCookie("Acd")));
}
}
function resetCookAcd() {
acd_add = {};
saveCookAcd();
alert("I dati del cookie Acd sono stati annullati");
}
// mw.loader.using( ['ext.wikiEditor.toolbar'], function(){
// $(document).ready( bloccaTools );
// });
// Blocco del pannello sin
var width = $("#mw-panel").width();
$("#p-logo").css("position", "fixed").css("top", "0");
$("#mw-panel").attr("style", "position:fixed;overflow:auto;left:0; bottom:0; width:" + width + "px;");
$(document).ready(readCookAcd);
function spittatore(testo) {
r = /[\,\;\.\:\-\_\'\ \"\*\+\?\!\|\[\]\{\}\(\)\=\n\/]+/g;
a1 = testo.split(r);
a2 = testo.match(r);
return [a1, a2];
}
function desplittatore(coppia) {
a1 = coppia[0];
a2 = coppia[1];
t = "";
for (var i = 0; i < a2.length; i += 1) {
t += a1[i] + a2[i];
}
t += a1[a1.length - 1];
return t;
}
function cod(testo) {
var l = produciLista(testo, "{{", "}}", 1, "{{");
for (var i = 0; i < l.length; i += 1) {
testo = testo.replace(l[i], l[i].replace(/\|/g, "__!__"));
}
l = produciLista(testo, "[[", "]]", 1, "[[");
for (var i = 0; i < l.length; i += 1) {
testo = testo.replace(l[i], l[i].replace(/\|/g, "__!__"));
}
return testo;
}
function parseTemplate(template, testo) {
if (testo == undefined) testo = leggiBox();
var cap=template.substring(0,1).toLocaleUpperCase()+template.substring(1);
testo=testo.replace("{{"+cap,"{{"+template);
var t = find_stringa(testo, "{{" + template, "}}", 1, "{{");
var l = [] // lista delle keys
var t = "0=" + t.substring(2, t.length - 2) // nome del template in parametro "0"
l.push["0"]
var ts = {}
var n = 1;
t = cod(t);
t = t.split("|");
// element for element
for (var i = 0; i < t.length; i += 1) {
// case param is positional
if (t[i].indexOf("=") == -1) {
t[i] = n + "=" + t[i];
n = n + 1;
}
var els = [];
els[0] = t[i].substring(0, t[i].indexOf("=")).trim();
els[1] = t[i].substring(t[i].indexOf("=") + 1).trim();
if (els[1][els[1].length - 1] == "\n") els[1] = els[1].substring(0, els[1].length - 1);
ts[els[0]] = decod(els[1]);
l.push(els[0]);
}
return [ts, l];
}
function decod(testo) {
testo = testo.replace(/__!__/g, "|");
return testo;
}
function templateObj(nomeTemplate) {
data = parseTemplate(nomeTemplate);
this.keys = data[1];
this.dict = data[0];
}
function rewriteTemplate(x) {
var testo = "";
$.each(x[1], function (indice, valore) {
if (valore != "0") testo += " | " + valore + " = " + x[0][valore] + "\n";
});
testo = "{{" + x[0]["0"] + "\n" + testo + "}}\n";
testo = testo.replace(/\n\s\|\s\d*\s=\s/g, "\n | ");
return testo;
}
//</source>