Utente:Alex brollo/LocalTools.js

'A Wikisource.

Notarella: Aroppo pubbreca putisse necessità 'e pulezzà 'a caché d' 'o navigatóre pe vedé 'e cagnamienti.

  • Firefox / Safari: Sprémme 'o buttóne maiuscole e ffà clic ncopp'a Recarreca, o pure spremme Ctrl-F5 o Ctrl-R (⌘-R ncopp'a Mac)
  • Google Chrome: spremme Ctrl-Shift-R (⌘-Shift-R ncopp'a nu Mac)
  • Internet Explorer/edge: Spremme 'o buttóne Ctrl pe' tramente ca faie click ncopp'a Refresh, o pure spremmere Ctrl-F5
  • Opera: Vaje addò 'o Menu → Mpustaziune (Opera → Mpustaziune ncopp' 'o Mac) e po' ncopp'a Privacy & sicurezza → Pulezza date d' 'o browser → Immaggene e file d' 'a cache.
importScript("Utente:Alex brollo/W.js");

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");

shortcut.add("Alt+7", function() {ws.memoRegexRun(); if (ws.leggiBox(0).indexOf("{{Rh")===-1) ws.newRi();});

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;});

shortcut.add("Alt+8",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])\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+6",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();
});



// rimuovi prima riga della pagina
shortcut.add("Alt+5",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+/, "");
    }
});
// 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");
}
ws.newButton("n↓↑","ws.toggleNote","es","Sposta le note");

ws.newButton("fp", "ws.full_page", "es","Nascondi-visualizza pannello sinistro");

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*.03)+"px",
	"top":Math.trunc(img.left+img.width*.03)+"px"
	});
	return false;
}
ws.newButton("img-","ws.img_reduce","es","Riduce immagine");
ws.newButton("poem","ws.incapsula('<poem>\\n','\\n</poem>')","es","Applica il tag poem alla selezione");