Usor:Alex brollo/LocalTools.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
importScript("Usor:Alex brollo/W.js");
$(".prp-page-container").css("height","100%"); // spostato in Alt+7 $(".prp-layout-is-horizontal #wpTextbox1").attr("rows","6");
ws.incapsula = function(pre, post, hl) {
if (hl === undefined)
hl = !1;
var selezione = [mw.activeElement,ws.selection()];
var sct = selezione[0].scrollTop;
while (selezione[1][1].slice(-1) == " ") {
selezione[1][1] = selezione[1][1].slice(0, -1);
selezione[1][2] = " " + selezione[1][2];
}
selezione[1][1] = pre + selezione[1][1] + post;
$(selezione[0]).val(selezione[1].join(""));
selezione[0].selectionEnd = selezione[1][0].length + selezione[1][1].length;
if (hl)
selezione[0].selectionStart = selezione[1][0].length;
else
selezione[0].selectionStart = selezione[0].selectionEnd;
selezione[0].focus();
return;
};
/* attivazione shortcuts*/
// shortcut.add("Ctrl+i", function () {$(mw.activeElement).textSelection( 'encapsulateSelection', { pre:"''", post: "''" } );});
shortcut.add("Ctrl+i", function () {$(mw.activeElement).textSelection( 'encapsulateSelection', { pre:"''", post: "''" } );});
shortcut.add("Ctrl+b", function () {$(mw.activeElement).textSelection( 'encapsulateSelection', { pre:"'''", post: "'''" } );});
shortcut.add("Ctrl+Shift+s", function () {$(mw.activeElement).textSelection( 'encapsulateSelection', { pre:"{{Sc|", post: "}}" } );});
shortcut.add("Ctrl+Shift+c", function () {$(mw.activeElement).textSelection( 'encapsulateSelection', { pre:"{{Ct|f=100%|v=1|L=0px|", post: "}}" } );});
shortcut.add("Ctrl+Alt+n", function() {
var t = ws.selection();
if (t[1].length === 0) {
t[1] = "<sup>nota</sup>";
} else {
t[1] = "<ref>" + t[1] + "</ref>";
}
ws.scriviSelAlt(t);
});
shortcut.add("Ctrl+Alt+g", function () {$(mw.activeElement).textSelection( 'encapsulateSelection', { pre:"{{Greek|", post: "|?}}" } );});
shortcut.add("Ctrl+Shift+f", ws.mostraTrovaSostituisci);
ws.newButton("FR","ws.mostraTrovaSostituisci","es","carica Find & Replace");
ws.Alt7= function() {
ws.autoPt();ws.memoRegexRun();
if (ws.leggiBox(0).indexOf("{{Rh")===-1) ws.newRi();
$(".prp-layout-is-horizontal #wpTextbox1").attr("rows","6");
};
shortcut.add("Alt+7",ws.Alt7);
ws.newButton("↓Alt7","ws.Alt7","es","cleanup");
shortcut.add("Ctrl+Alt+1",function () {$(".quality1 input").click(); $("#wpSave").click(); return false;});
shortcut.add("Ctrl+Alt+3",function () {$(".quality3 input").click(); $("#wpSave").click(); return false;});
shortcut.add("Alt+0",function () {$(".quality0 input").click(); $("#wpSave").click(); return false;});
ws.Alt8=function() {
// eliminazione acapo che esclude sia i testi <poem> che le righe che iniziano con ";:#*" (liste html)
var editbox = document.getElementsByName('wpTextbox1')[0];
var poemNumber=0;
var listaGlobale=[];
// fase 1: codifica
if (editbox.value.indexOf("<poem") != -1) {
lista = ws.produciLista(editbox.value, "<poem", "</poem>", 1);
listaGlobale=[].concat(lista);
poemNumber=lista.length;
for (i = 0; i <= lista.length - 1; i = i + 1) {
marcatore = "###" + i + "###";
editbox.value = editbox.value.replace(lista[i], marcatore);
}
}
editbox.value=editbox.value.replace("{{Poem", "{{poem").replace("{{Mlb", "{{mlb");
if (editbox.value.indexOf("{{poem") != -1) {
lista = produciLista(editbox.value, "{" + "{poem", "}}", 1,"{{");
listaGlobale=listaGlobale.concat(lista);
for (i = 0; i <= lista.length - 1; i = i + 1) {
marcatore = "###" + (i+poemNumber) + "###";
editbox.value = editbox.value.replace(lista[i], marcatore);
}
}
if (editbox.value.indexOf("{{mlb") != -1) {
lista = ws.produciLista(editbox.value, "{" + "{mlb", "}}", 1,"{{");
listaGlobale=listaGlobale.concat(lista);
for (i = 0; i <= lista.length - 1; i = i + 1) {
marcatore = "###" + (i+poemNumber) + "###";
editbox.value = editbox.value.replace(lista[i], marcatore);
}
}
// fase2: eliminazione acapo singoli, con conservazione dei multipli
//if (mw.config.get("wgTitle").indexOf("Trattato di archeologia (Gentile).djvu")==-1) {
editbox.value = editbox.value.replace(/ +\n/g,"\n");
editbox.value = editbox.value.replace(/([^>}\n])\n([^<\n\:\;\*\#\|\{])/g, '$1 $2'); //linux
editbox.value = editbox.value.replace(/([^>}\r\n])\r\n([^<\r\n\:\;\*\#\|\{])/g, '$1 $2'); //windows
// }
// eliminazione sequenze di spazi, sostituiti da spazio singolo
editbox.value = editbox.value.replace(/ +/g, ' ');
// sostituzione spazio dopo marcatore
editbox.value=editbox.value.replace(/### /g,"###\n");
// fase 3: decodifica
if (editbox.value.indexOf("###0###") != -1) {
for (i = 0; i <= listaGlobale.length - 1; i = i + 1) {
marcatore = "###" + i + "###";
editbox.value = editbox.value.replace(marcatore, listaGlobale[i]);
}
}
// fase 4: sistemazione a capo attorno a poem
//editbox.value=editbox.value.replace(/ <poem>/g,"\n<poem>").replace(/<\/poem> /g,"</poem>\n");
editbox.value=editbox.value.replace(/### /g,"###\n");
//updatePreview();
};
shortcut.add("Alt+8",ws.Alt8);
ws.newButton("Alt8", "ws.Alt8()", "es","unisci linee");
ws.Alt6=function() {
textbox = document.getElementsByName('wpTextbox1')[0];
testo = textbox.value;
poems = ws.produciLista(testo, "<poem>", "</poem>", 1);
for (i = 0; i < poems.length; i += 1) {
testo = testo.replace(poems[i], "[#" + i + "#]");
}
testo = testo.replace(/ \n/g, "\n").replace(/([\.\?\!]\n)([^\n])/g, '$1\n$2');
for (i = 0; i < poems.length; i += 1) {
testo = testo.replace("[#" + i + "#]", poems[i]);
}
textbox.value = testo;
//updatePreview();
};
shortcut.add("Alt+6",ws.Alt6);
ws.newButton("Alt6", "ws.Alt6()", "es","aggiusta paragrafi");
// rimuovi prima riga della pagina
ws.Alt5= function() {
var editbox = document.getElementsByName('wpTextbox1')[0];
if (editbox.value.substring(0, 6) == "<poem>") {
editbox.value = editbox.value.replace(/<poem\>.+\n/, "<poem>");
} else {
editbox.value = editbox.value.replace(/.+\n+/, "");
}
};
shortcut.add("Alt+5",ws.Alt5);
ws.newButton("Alt5", "ws.Alt5()", "es","elimina prima riga body");
// toggling fra le due sintassi di section
shortcut.add("Ctrl+Alt+s", function() {
var r=/^##.+##$/gm;
if (r.test(ws.leggiBox())) {
ws.restore_lst();
} else {
ws.easy_section_syntax();
}
});
/* attivazione buttons*/
// toggle maiuscole-minuscole nella selezione
ws.up_low=function(){
var t=ws.selection();
if(t[1]===t[1].toLocaleUpperCase()) t[1]=t[1].toLocaleLowerCase();else t[1]=t[1].toLocaleUpperCase();
ws.scriviSel(t);};
ws.newButton("A↔a", "ws.up_low()", "es","Applica maiuscolo/minuscolo alla selezione, alternandole");
// Nascondi-visualizza pannello sinistro
ws.full_page=function(){
$("#mw-panel").toggle();
if ($("#content").css("margin-left")=="0px")
$("#content").css("margin-left", "176px");
else
$("#content").css("margin-left", "0");
};
// divide la pagina in due section s1 e s2, oppure una section s2 in una s2 e s3, usando come punto di separazione
// la posizione del puntatore. Usa sel()
ws.newSections = function() {
var s=ws.selection();
if (s[2].indexOf('<section end="s2" />')===-1) {
s[0]='<section begin="s1" />'+s[0]+'<section end="s1" />';
s[2]='<section begin="s2" />'+s[2]+'<section end="s2" />';
}
else {
s[0]=s[0]+'<section end="s2" />';
s[2]='<section begin="s3" />'+s[2].replace('<section end="s2" />','<section end="s3" />');
}
ws.scriviBox(s[0]+s[1]+s[2]);
return;
};
ws.newButton("n↓↑","ws.toggleNote","es","Sposta le note");
ws.newButton("fp", "ws.full_page", "es","Nascondi-visualizza pannello sinistro");
ws.newButton("sections", "ws.newSections()", "es","splitta in sezioni");
/*ws.img_enlarge=function(){
var img=$(".prp-page-image img")[0];
$(".prp-page-image img").css({"width":Math.trunc(img.width*1.12)+"px",
"height":Math.trunc(img.height*1.12)+"px",
"top":Math.trunc(img.top-img.height*.03)+"px",
"top":Math.trunc(img.left-img.width*.03)+"px"
});
return false;
}
ws.newButton("img+","ws.img_enlarge","es","Ingrandisce immagine");
ws.img_reduce=function(){
var img=$(".prp-page-image img")[0];
$(".prp-page-image img").css({"width":Math.trunc(img.width/1.12)+"px",
"height":Math.trunc(img.height/1.12)+"px",
"top":Math.trunc(img.top+img.height*0.03)+"px",
"left":Math.trunc(img.left+img.width*0.03)+"px"
});
return false;
};
ws.newButton("img-","ws.img_reduce","es","Riduce immagine");
*/
ws.ctplus=function() {
var t=ws.selection();
t[1]=t[1].split("\n");
t[1]=t[1].filter(function(e){return $.trim(e).length>0});
for (i=0;i<t[1].length;i+=1) {
t[1][i]="{{Ct|f=100%|v=1|"+t[1][i]+"}}";
}
t[1]=t[1].join("\n");
ws.scriviBox(t.join(""));
return false;
};
ws.tableMaker = function() {
var t = ws.selection();
var tabella = t[1];
tabella=tabella.replace(/\|\|/g,"\t");
tabella=tabella.split("\n");
for (i = 0; i < tabella.length; i += 1) {
tabella[i] = "|-\n|" + tabella[i].replace(/\t/g, "||");
}
t[1] = "{|\n" + tabella.join("\n") + "\n|}\n";
//scriviBox(t.join(""));
ws.scriviSel(t);
};
ws.newButton("tableM", "ws.tableMaker()", "es","Trasforma in tabella wiki il codice copiaincollato da Excel");
ws.newButton("Ct+","ws.ctplus","es","Applica Ct su più righe");
ws.newButton("poem","ws.incapsula('<poem>\\n','\\n</poem>')","es","Applica il tag poem alla selezione");
ws.newButton("Sc","ws.incapsula('{{Sc|','}}')","es","Applica il tl Sc alla selezione");
ws.newButton("{{|}}","ws.incapsula('{{|','}}')","es","Applica tl vuoto alla selezione");
ws.newButton("#tag:ref","ws.incapsula('{{#tag:ref|','}}')","es","Applica tag ref alla selezione");