MediaWiki:Gadget-strumentiRiletura.js

Ocio: Daspò ver salvà, podaria esare neçesario snetare ła cache dal propio navegadore web par vedare i canbiamenti.

  • Firefox / Safari: tegner strucà el boton de łe letare grande Shift e schiciare sora Ricarga, o se nò struca Ctrl-F5 o Ctrl-R (⌘-R so Mac)
  • Google Chrome: strucare Ctrl-Shift-R (⌘-Shift-R so on Mac)
  • Internet Explorer / Edge: tegner strucà el boton Ctrl e schiciare so Ajorna, o sinò Ctrl-F5
  • Opera: Va in tel Menu → Inpostasion (Opera → Prefarense so on Mac) e pò in Privacy & sicuresa → Sneta dati del navegadore → Imajini e file in te ła cache.
/* copià da https://it.wikisource.org/wiki/Utente:Alex_brollo/regextool.js */

/** create menu */
if (mw.config.get('wgCanonicalNamespace') != 'Index' && (mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit') ) {
	$(document).ready(function() {
		/* get elements */
		// note: these must be global.
		editbox = document.getElementById('wpTextbox1');
		editreason = document.getElementById('wpSummary');
		try {
			sidebar = document.getElementById('p-navigation').parentNode;
		}
		catch(err) {
			console.log( 'Regex menu framework rfmenu() aborted due to unknown error. This (rare) issue will be fixed in the eventual rewrite.' );
			return;
		}
	
		/* add CSS */
		/*appendCSS('<style type="text/css">'
			+ '#p-regex li { list-style:none !important; }'
			+ '#p-regex a { color:gray !important; }')
			; */
	
		/* create menu */
		var container = document.createElement('div');
		container.setAttribute('class','portal persistent vector-menu vector-menu-portal');
		container.setAttribute('id','p-regex');
	
		sidebar.appendChild(container);
	
		var header = document.createElement('h3');
		header.setAttribute('class', 'vector-menu-heading');
		header.appendChild(document.createTextNode('Strumenti par la riletura'));
		container.appendChild(header);
	
		var toolbox = document.createElement('div');
		toolbox.setAttribute('class','vector-menu-content');
		container.appendChild(toolbox);
	
		toollist = document.createElement('ul');
		toollist.setAttribute('class', 'vector-menu-content-list');
		toolbox.appendChild(toollist);
	
		regexTool = function(name, functionname, descrizione) {
			if (!descrizione) {
				descrizione = name;
			}
			var newline = document.createElement('li');
			var newlink = document.createElement('a');
			newlink.setAttribute('href','javascript:'+functionname);
			newlink.setAttribute('title', descrizione);
			newlink.setAttribute('class','sidebar-link');
			newlink.appendChild(document.createTextNode(name));
		
			newline.appendChild(newlink);
			toollist.appendChild(newline);
		};
	
		/* load user-defined sidebar links */
		regexTool('PostOCR','postOCR()');
		regexTool('Inisiale maiuscola', 'inizialeMaiuscola()');
		regexTool('Otave','ottave()');
		regexTool('Nùmaro riga ogni 3','numeroRiga(2, 3)');
		regexTool('Nùmaro riga ogni 4','numeroRiga(2, 4)');
		regexTool('Nùmaro riga ogni 5','numeroRiga(2, 5)');
		regexTool('Num. riga ogni fine strofa','numeroRiga(1)');
		regexTool('Cava tuti i {{R}}','numeroRiga(0)', "Cava la numerassion dei versi");
		
/* fine parte copià da https://it.wikisource.org/wiki/Utente:Alex_brollo/regextool.js */


		/* Coression standard */
		postOCR = function () {
			var editbox = document.getElementById("wpTextbox1");
			editbox.value = editbox.value.replace(/(\S+)[ ]+/g, "$1 ")
				.replace(/ ,/g, ",")
				.replace(/ ;/g, ";")
				.replace(/ :/g, ":")
				.replace(/ \./g, ".")
				.replace(/ !/g, "!")
				.replace(/ \?/g, ";")
				.replace(/'1/g, "'l")
				.replace(/1'/g, "'l'")
				.replace(/I'/g, "l'")
				.replace(/l' /g, "l'")
				.replace(/'l'/g, "l'")
				.replace(/L' /g, "L'")
				.replace(/h' /g, "h'")
				.replace(/d' /g, "d'")
				.replace(/D' /g, "D'")
				.replace(/m' /g, "m'")
				.replace(/M' /g, "M'")
				.replace(/n' /g, "n'")
				.replace(/N' /g, "N'")
				.replace(/s' /g, "s'")
				.replace(/S' /g, "S'")
				.replace(/t' /g, "t'")
				.replace(/T' /g, "T'")
				.replace(/v' /g, "v'")
				.replace(/V' /g, "V'")
				.replace(/ \n/g, "\n")
				.replace(/-\n/g, "")
				.replace(/é/g, "è")
				.replace(/ó/g, "ò")
				.replace(/á/g, "à")
				.replace(/ piu /g, " più ")
				.replace(/zja/g, "zia")
				.replace(/zjo/g, "zio")
				.replace(/cbi/g, "chi")
				.replace(/cbe/g, "che")
				.replace(/gbi/g, "ghi")
				.replace(/gbe/g, "ghe")
				.replace(/cussi/g, "cussì")
				.replace(/Cussi/g, "Cussì")
				.replace(/perche/g, "perchè")
				.replace(/Perche/g, "Perchè")
				.replace(/ piu /g, " più ")
				.replace(/ Più /g, " Più ")
				.replace(/ piu,/g, " più,")
				.replace(/ Più,/g, " Più,")
				.replace(/ piu;/g, " più;")
				.replace(/ Più;/g, " Più;")
				.replace(/piii/g, "più")
				.replace(/ pb /g, " pò ")
				.replace(/ p6 /g, " pò ")
				.replace(/ hb /g, " hò ")
				.replace(/ alia /g, " alla ")
				.replace(/ va /g, " và ")
				.replace(/ ancuo /g, " ancuò ")
				.replace(/quesr/g, "quest")
				.replace(/ y /g, ", ")
				.replace(/ j /g, "; ")
				.replace(/ j\n/g, ";\n")
				.replace(/ gb /g, " gò ")
				.replace(/ y\n/g, ",\n")
				.replace(/ 3 /g, ", ")
				.replace(/ 3\n/g, ",\n")
				.replace(/eh'/g, "ch'")
				.replace(/akro/g, "altro")
				.replace(/akri/g, "altri")
				.replace(/akra/g, "altra")
				.replace(/akre/g, "altre")
				.replace(/alrro/g, "altro")
				.replace(/alrri/g, "altri")
				.replace(/alrra/g, "altra")
				.replace(/alrra/g, "altre")
				.replace(/etco/g, "etto")
				.replace(/etci/g, "etti")
				.replace(/coral/g, "cotal")
				.replace(/Coral/g, "Cotal")
				.replace(/([aeiou])u([aeiou])/g, "$1v$2")
				.replace(/vn/g, "un")
				.replace(/f([bcdgmnpqtv])/g, "s$1")
				.replace(/\s+$/, '');
		};
		
		
		
		/* Zonta el template:O al testo */
		ottave = function() {
		
			var testoCasella = document.getElementById("wpTextbox1").value;
			var poemBegin = testoCasella.lastIndexOf("<poem>");
			var poemEnd = testoCasella.lastIndexOf("</poem>");
			var prima = testoCasella.substring(0, poemBegin+6);
			var dopo = testoCasella.substring(poemEnd);
			var lines = testoCasella.substring(poemBegin+6, poemEnd).split("\n");
		
			var center = false;
			var begin = false;
		
			var num = parseInt(prompt("da che numero parto?", "1"));
		
			for (var i=0; i < lines.length; i++) {
		
				if (lines[i].toLowerCase().lastIndexOf("<"+"center>") > -1) center = true;
				if (lines[i].replace(/\s/g,"") === "") begin = true;
				else if (!center && begin) {
					begin = false;
					lines[i] = scriviNumero(lines[i], num, "O");
					num++;
				}
		
				if (lines[i].toLowerCase().lastIndexOf("</center>") > -1) center = false;
			}
		
			var out = lines[0];
			for (var j=1; j < lines.length; j++) {
				out = out + "\n" + lines[j];
			}
			document.getElementById("wpTextbox1").value = prima + out + dopo;
		};
		
		
		/* sotto-funzione di numeroRiga()
		 * aggiunge il numero num alla riga line
		 */
		scriviNumero = function(line, num, tmpl) {
		
			var str = line;
			var n = 0;
			if (tmpl === undefined) {
				tmpl = "R";
			}
		
			//salta gli spazi ad inizio riga
			while (str.charAt(0) && str.charAt(0) == ' ') {
				str = str.substring(1);
				n++;
			}
		
			//salta gli ":" ad inizio riga
			while (str.charAt(0) && str.charAt(0) == ':') {
				str = str.substring(1);
				n++;
			}
		
			if (n > 0) line = line.substring(0, n) + "{"+"{"+tmpl+"|" + num + "}}" + line.substring(n);
			else line = "{" + "{"+tmpl+"|" + num + "}}" + line;
		 
			return line;
		};
		
		
		/* aggiunge il numero di riga
		 * con mod=1 mette il numero ogni ultimo verso del paragrafo
		 * con mod=2 mette il numero ogni x righe
		 * 
		 * TODO: escludere le righe con {{Centra}}
		 */
		numeroRiga = function(mod, x) {
		
			var testoCasella = document.getElementById("wpTextbox1").value;
			// cancella tutti gli R
			if (mod===0) {
				while (find_stringa(testoCasella,"{{R|","}}",1) !== "") {
					testoCasella=testoCasella.replace(find_stringa(testoCasella,"{{R|","}}",1),'');
				}
				while (find_stringa(testoCasella,"{{r|","}}",1) !== "") {
					testoCasella=testoCasella.replace(find_stringa(testoCasella,"{{r|","}}",1),'');
				}
				document.getElementById("wpTextbox1").value=testoCasella;
				return;
			}
		
			//se manca il poem, mettilo
			if (testoCasella.indexOf("<poem>") == -1) {
				testoCasella = '<poem>' + testoCasella;
			}
			if (testoCasella.indexOf("</poem>") == -1) { 
				testoCasella = testoCasella + '</poem>';
			}
		
			//prende il poem in cui si trova il cursore
			var pos = document.getElementById("wpTextbox1").selectionStart;
			begin = testoCasella.substring(0, pos+6).lastIndexOf("<poem>");
			if (begin == -1) { return; }
			end = testoCasella.substring(begin).indexOf("</poem>") + testoCasella.substring(0, begin).length;
		
			var prima = testoCasella.substring(0, begin+6);
			var dopo = testoCasella.substring(end);
		
			//scomponi il testo in singole righe
			var lines = testoCasella.substring(begin+6, end).split("\n");
		
			var num = 1;
			var center = false;
		
			//solo in namespace Pagina, fai scegliere all'utente da che numero partire (l'ultimo numero della pagina prima)
			if (mw.config.get('wgCanonicalNamespace') == "Page") {
		
				verso = "1";
		 		num = parseInt(prompt("da che numero parto?", verso));
			}
		
			num--;
		
			for (var i=0; i < lines.length; i++) {
		
				//non considerare il testo dentro el tag center
				if (lines[i].toLowerCase().lastIndexOf("<" + "center>") > -1) center = true;
		
				//salta le righe vuote
				if (!center && lines[i].replace(/\s/g,"") !== "") {
					num++;
		
					//in modalita' 1, controlla che la prossima riga sia l'ultima o una riga bianca
					if (mod == 1 && (i+1 >= lines.length || lines[i+1].replace(/\s/g,"") === "") ) {
						lines[i] = scriviNumero(lines[i], num);
					}
		
					if (mod == 2 && num % x === 0) {
						lines[i] = scriviNumero(lines[i], num);
					}
				}
		
				if (lines[i].toLowerCase().lastIndexOf("</center>") > -1) center = false;
			}
		
			//rimetti insieme le righe
			var out = lines[0];
			for (var j=1; j < lines.length; j++) {
				out = out + "\n" + lines[j];
			}
			document.getElementById("wpTextbox1").value = prima + out + dopo;
		};
		
		lt = function(testo) {
			var caratteri=" ;:*#'-—(";
			while (testo.length>0 && (caratteri.indexOf(testo.substr(0,1))>-1 || testo.substr(0,4)=="{{R|" || testo.substr(0,4)=="{{O|" ) ) {
				if (testo.substr(0,4)=="{{R|") {
					var r=find_stringa(testo,"{{R|","}}",1,"{{"); 
					testo=testo.replace(r,"");
				}
				else if (testo.substr(0,4)=="{{O|") {
					var s=find_stringa(testo,"{{O|","}}",1,"{{"); 
					testo=testo.replace(s,"");
				}
				else {
					testo=testo.substr(1); 
				}
			} 
			return testo; 
		};
		
		inizialeMaiuscola = function() {
			editbox = document.getElementsByName('wpTextbox1')[0];
			var txt=editbox.value;
			txt=txt.split("\n");
			for (var i=0; i<txt.length; i++) {
				var riga=lt(txt[i]);
				var rigaNew=riga.substr(0,1).toLocaleUpperCase()+riga.substr(1);
				if (riga != rigaNew) {
					txt[i]=txt[i].replace(riga,rigaNew);
				}
			}
			txt=txt.join("\n");
			editbox.value=txt;
		};

	});
}
Traesto fora da Wikipèdia - L'ençiclopedia łìbara e cołaboradiva in łéngua Vèneta "https://vec.wikisource.org/w/index.php?title=MediaWiki:Gadget-strumentiRiletura.js&oldid=72570"