MediaWiki:Common.js

Da Wikisource

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.
/* importassion script da www.wikisource.org  */
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:OCR.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:Compare.js&action=raw&ctype=text/javascript');

// Ricerca in Wikidata
mw.loader.load("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");

/* tradussion dei messagi javascript  */
self.ws_messages = {
	'iwtrans':'El so testo el vien da', 
	'iwtrans2':'El so testo el vien da un altro sotodominio de Wikisource.',

	'compare_with': 'Confronto con:',
	'compare_texts': 'Confronta testi'
};


//disable ThomasV's "simplified lst"
self.proofreadpage_raw_lst=true;

/* conta il numero di occorrenze di stringa dentro testo*/
function count(testo, stringa) {
	n = 0;
	while (testo.indexOf(stringa) > -1) {
		n++;
		testo = testo.replace(stringa, "");
	}
	return n;
}

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 selection(area) {
	if (area === undefined) {
		if (mw.config.get('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;
}

//boton par mostrar e scondar la wikiguida
function toggleWikiGuida() {
	$('#wikiguida').toggle();
	if ($('#wikiguida').css('display') != 'none') {
		$('#wikiguidaButton').text('WikiGuida▲');
		
		//fix: a la prima apertura l'imagine la se vede picenina, va a saver perché...
		$('.mwEmbedPlayer img').width('750');
		$('.mwEmbedPlayer img').height('422');
		$('.mwEmbedPlayer img').css('top', '0px');
	}
	else {
		$('#wikiguidaButton').text('WikiGuida▼');
	}
}
$(document).ready(function() {
	$('.page-Pagina_prinsipale #intestazion b').append(' · <a id="wikiguidaButton" href="javascript:void(0)" onclick="toggleWikiGuida()">WikiGuida▼</a>');
});


/* in modifica di un Indice, mostra l'icona qualità corrispondente */
function setQualityIconIndex() {
	var progress = $('[name=wpprpindex-Progress]');
	progress.next().remove();

	if (progress.val() == 1) {
		progress.after('<img src="//upload.wikimedia.org/wikipedia/commons/thumb/3/34/25%25.svg/18px-25%25.svg.png"/>');
	}
	else if (progress.val() == 2) {
		progress.after('<img src="//upload.wikimedia.org/wikipedia/commons/thumb/c/c2/50%25.svg/18px-50%25.svg.png"/>');
	}
	else if (progress.val() == 3) {
		progress.after('<img src="//upload.wikimedia.org/wikipedia/commons/thumb/4/49/75%25.svg/18px-75%25.svg.png"/>');
	}
	else if (progress.val() == 4) {
		progress.after('<img src="//upload.wikimedia.org/wikipedia/commons/thumb/2/24/100_percent.svg/18px-100_percent.svg.png"/>');
	}
}


/* Qualità indice
 *
 * ciapà da http://wikisource.org/wiki/MediaWiki:IndexForm.js 
 */
$(document).ready(function() {
	mw.loader.using('ext.proofreadpage.index', function () {
		if (mw.config.get('wgCanonicalNamespace') == 'Index') {
			
			ws_messages.progress_4 = 'Rileto';
			ws_messages.progress_3 = 'Conpleto';
			ws_messages.progress_2 = 'Da sistemar';
			ws_messages.progress_1 = 'Inconpleto';
			
			var f = document.editform;
			if (f) {
				f = document.getElementsByName('wpprpindex-Image')[0];
				if (f && f.value === "") 
					f.value="1";
				f = document.getElementsByName('wpprpindex-Pages')[0];
				if (f && f.value === "") 
					f.value="<pagelist />";
	
				var a = document.getElementsByName('wpprpindex-Progress')[0];
				if (a) {
					value = a.value;
					a.parentNode.innerHTML='<select name="wpprpindex-Progress">'
						+'<option value="1" selected="true">' + ws_messages.progress_1 + '</option>'
						+'<option value="2">' + ws_messages.progress_2 + '</option>'
						+'<option value="3">' + ws_messages.progress_3 + '</option>'
						+'<option value="4">' + ws_messages.progress_4 + '</option>'
						+'</select>';
					a = document.getElementsByName('wpprpindex-Progress')[0];
					for (var i=0; i < a.length; i++) {
						if (a[i].value == value) a[i].selected = true;
					}
					
					setQualityIconIndex();
					$('select[name=wpprpindex-Progress]').change(function() {
						setQualityIconIndex();
					});
				}
			}
		}
	 });
});


function elabIndex_onEdit() {
	// scondi area dati su Indice
	if (mw.config.get('wgCanonicalNamespace') == 'Index' && $("[name=wpprpindex-Interwiki]").length > 0) {
		var testoInterwiki = $("[name=wpprpindex-Interwiki]").val();
		areaDati = find_stringa(testoInterwiki, "<!--area dati-->", "<!--fine dati-->", 1);
		if (areaDati !== "") $("[name=wpprpindex-Interwiki]").val(testoInterwiki.replace(areaDati, ""));
	}
}
$(document).ready(elabIndex_onEdit);


function elab_onEdit() {
	//cava i spassi bianchi inutili in fondo a le righe
	if ($('#wpTextbox1').length > 0) {
		if (mw.config.get('wgCanonicalNamespace') === '' || mw.config.get('wgCanonicalNamespace') == 'Page') {
			$('#wpTextbox1').val($('#wpTextbox1').val().replace(/[ ]+$/gm, ''));
		}
	}
}
$(document).ready(elab_onEdit);


/* OCR automatico alla creazione di una nuova Pagina */
function postOCRAutomatico() {
	if (mw.config.get('wgCanonicalNamespace') == "Page" && mw.config.get('wgAction') == "edit" && mw.config.get('wgArticleId') === 0) {
		mw.loader.using('ext.proofreadpage.page', function () {
			var editbox = document.getElementsByName('wpTextbox1')[0];
			
			editbox.value = editbox.value
			.replace(/'1/g, "'l")
			.replace(/1'/g, "'l'")
			.replace(/([a-zA-Z])1/g, '$1l')
			.replace(/I'/g, "l'")
			.replace(/l' /g, "l'")
			.replace(/'l'/g, "l'")
			.replace(/ \n/g, '\n')
			.replace(/-\s*\n/g, '')
			.replace(/¬\s*\n/g, '')
			.replace(/- /g, '― ')
			.replace(/ì'/g, 'l\'')
			.replace(/1\*/g, 'l\'')
			.replace(/\*1/g, '\'l')
			.replace(/\* /g, '\'')
			.replace(/ V /g, 'l\'')
			.replace(/ ,/g, ",")
			.replace(/,([a-zA-Z])/g, ", $1")
			.replace(/ ;/g, ";")
			.replace(/ :/g, ":")
			.replace(/ \./g, ".")
			.replace(/ !/g, "!")
			.replace(/ \?/g, "?")
			.replace(/\( /g, "(")
			.replace(/ \)/g, ")")
			.replace(/£/g, "E")
			.replace(/ſ/g, 'f')
			.replace(/º/g, 'o')
			.replace(/ucla/g, 'uela')
			.replace(/gbe/g, 'ghe')
			.replace(/Gbe/g, 'Ghe')
			.replace(/cbe/g, 'che')
			.replace(/Cbe/g, 'Che')
			.replace(/gbi/g, 'ghi')
			.replace(/Gbi/g, 'Ghi')
			.replace(/cussi/g, 'cussì')
			.replace(/Cussi/g, 'Cussì')
			.replace(/cbi/g, 'chi')
			.replace(/Cbi/g, 'Chi')
			.replace(/erchfc/g, 'erchè')
			.replace(/ deir /g, ' dell\'')
			.replace(/ air /g, ' all\'')
			.replace(/ neir /g, ' nell\'') 
			.replace(/l'e /g, "l'è ")
			.replace(/ perche /g, ' perchè ')
			.replace(/ poiche /g, ' poichè ')
			.replace(/Perche /g, 'Perchè ')
			.replace(/Poiche /g, 'Poichè ')
			.replace(/ piu /g, ' più ')
			.replace(/ luti /g, ' tuti ')
			.replace(/ luto /g, ' tuto ')
			.replace(/ slo /g, ' sto ')
			.replace(/ sla /g, ' sta ')
			.replace(/ sli /g, ' sti ')
			.replace(/ sle /g, ' ste ')
			.replace(/ Y /g, ' l\'')
			.replace(/ 6 /g, ' ò ')
			.replace(/qn/g, 'qu')
			.replace(/([aeiou])u([aeiou])/g, '$1v$2')
			.replace(/vn/g, 'un')
			.replace(/Vn/g, 'Un')
			.replace(/‘/g, "'")
			.replace(/`/g, "'")
			.replace(/ä/g, "à")
			.replace(/ë/g, "è")
			.replace(/lrr/g, 'ltr')
			.replace(/Digiti\s*zed by .*/gi, '')
			.replace(/([bcdfghlmnprstvzBCDFGHLMNPRSTV])' /g, '$1\'')
			.replace(/eh'/g, 'ch\'')
			.replace(/slr/g, 'str')
			.replace(/\s+$/, '');
			
			//inserisce un a capo all'inizio del footer (per il bug 26028)
			footer = $('[name=wpFooterTextbox]');
			if ( !footer.val().match(/^\n/) ) {
				footer.val( '\n' + footer.val() );
			}
		});
	}
}
$(document).ready(postOCRAutomatico);


//fix bug della barra qualità (le colonne con larghezza 0% vengono mostrate con larghezza 1px sui browser WebKit)
$(document).ready(function() {
	$('table.pr_quality td').each(function(index) {
		//sistemo mettendo display:none alle colonne di larghezza zero
		if ($(this).attr('style').indexOf('width:0') != -1) {
			$(this).hide();
		}
	});
});
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:Common.js&oldid=74746"