MediaWiki:Gadget-autoreEdizioni.js

Da Wikisource.

Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
$(function() {
	if (mw.config.get("wgCanonicalNamespace") == 'Autore' || mw.config.get("wgCanonicalNamespace") == 'Opera') {
		alreadyDone = [];
		$('.tl-testo').each(function(i) { 
			indice = $(this).find('.tl-testo-indice a').attr('title');
			if (indice !== undefined) {
				if (alreadyDone[indice] === undefined) {
					alreadyDone[indice] = true;
				
					$.ajax({
						url: "/w/index.php?&title=" + indice
					}).done(function(response) {
						d = $('#dati', response);
						if (d.data('citta').length > 0 || d.data('editore').length > 0) {
							titolo = $('#firstHeading', response).text();
							if (titolo == '') 
								titolo = $('.page-heading h1', response).text(); //mobile
														
							$('.tl-testo').each(function(i) { 
								indice = $(this).find('.tl-testo-indice a').attr('title');
								if (indice == titolo) {
									str = '';
									anchor = $(this);
									if (anchor.parent().find('ul, ol').length === 0)
										anchor = anchor.parent();
									
									if (anchor.find('.tl-testo-edizione').length === 0) {
									
										if (!(anchor.text().trim().endsWith('.')))
											str += '.';
										str += ' <small class="tl-testo-edizione" title="Edizione utilizzata per la trascrizione di questo testo">';
										
										if (d.data('curatore').length > 0) {
											str += 'A cura di ' + d.data('curatore').replace(/\//g, ', ') + ', ';
										}
						
										if (d.data('citta').length > 0) {
											str += d.data('citta') + ', ';
										}
										if (d.data('editore').length > 0) {
											str += d.data('editore') + ', ';
										}
										if (d.data('anno')) {
											str += d.data('anno');
										} else {
											str += 's. d.';
										}
										str += '</small>';
										anchor.append(str);
									}
								}
							});
						}
					});
				}
			}
		});
	}
});