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 ( mw, $ ) {
	function initTabs() {}
});

activateCancellazione = $('.page-Categoria_Da_cancellare_subito, .ns-14, .ns-special:not(.mw-special-Recentchanges)');
$(document).ready(function() {
	if (typeof activateCancellazione === 'function') {
		activateCancellazioneUltraRapida();
	}
	
	if (mw.config.get('wgNamespaceNumber') == 0 && mw.config.get('wgTitle').indexOf('/') > -1) {
		// casella piccola nelle sottopagine ns0
		$('.CodeMirror').css('height', '150px');
	} else if (mw.config.get('wgNamespaceNumber') == 3 && mw.config.get('wgAction')  == 'view') {
		//scrolla in fondo quando vai in view su una pagina di discussione
		$(document).scrollTop($(document).height());
	} else if ($('.page-Utente_Candalua').length) {
		//get bot's last edit timestamp
		$.getJSON('/w/api.php?action=query&list=usercontribs&ucuser=CandalBot2&uclimit=1&format=json&continue', function(jsonResp) {
			if (jsonResp === undefined) {
				console.log('Candalua vector.js: la risposta alla chiamata ajax è undefined!');
				return;
			}
			var lastEditTS = new Date(jsonResp.query.usercontribs[0].timestamp);
			var diffDays = Math.floor( ( new Date() - lastEditTS ) / 1000/60/60/24 );
			var giorniFa = $('<b>' + diffDays + ' giorni fa</b>');
			if (diffDays < 5) 
				giorniFa.css('color', 'green');
			else
				giorniFa.css('color', 'red');
			var readableTimestamp = lastEditTS.getDate() + '/' + (lastEditTS.getMonth()+1) + '/' + lastEditTS.getFullYear() + ' ' + ('00' + lastEditTS.getHours()).slice(-2) + ':' + ('00' + lastEditTS.getMinutes()).slice(-2);
			$('#CandalBotLastEditTime span').html(readableTimestamp + ', ').append(giorniFa);
		});
	}
});


var customCSSEnabled = true;

$('body').append('<div style="position:fixed; top:0; left:0; z-index: 2000;"><a href="javascript:void()" id="customCSSControl" onclick="toggleCustomCSS()"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/3/33/High-contrast-view-restore.svg/20px-High-contrast-view-restore.svg.png"/></a></div>');


//abilita/disabilita css personalizzato
function toggleCustomCSS() {
  if (customCSSEnabled) {
    $('link[href*="user=Candalua"]').attr('disabled', 'disabled');
    customCSSEnabled = false;
  }
  else {
    $('link[href*="user=Candalua"]').prop('disabled', false);
    customCSSEnabled = true;
  }
}

function getPageQuality() {
  text = document.getElementById("wpTextbox1").value;
  m = text.match(/<pagequality level=\"([0-4])\" user=\".*?\" \/>/);
  if (m) return m[1];
}

//OCR automatico alla creazione di una nuova Pagina
function postOCRPersonale() {
  if (mw.config.get('wgCanonicalNamespace') == "Page" && mw.config.get('wgAction') == "edit" && mw.config.get('wgArticleId') === 0) {
    var editbox = document.getElementsByName('wpTextbox1')[0];
    editbox.value = editbox.value.replace(/'/g, '’')
    .replace(/’’’/g, '\'\'\'')
    .replace(/’’/g, '\'\'')
    .replace(/e’/g, 'e’ ')
    .replace(/e’  /g, 'e’ ')
    .replace(/é/g, 'è')
    .replace(/E’ /g, 'È ')
    .replace(/v’ /g, 'v’')
    .replace(/n’ /g, 'n’')
    .replace(/s’ /g, 's’')
    .replace(/t’ /g, 't’')
    .replace(/m’ /g, 'm’')
    .replace(/1\*/g, 'l’')
    .replace(/l\*/g, 'l’')
    .replace(/\*/g, '’')
    .replace(/i’/g, 'l’')
    .replace(/1’/g, 'l’')
    .replace(/l’ /g, 'l’')
    .replace(/ T /g, ' l’')
    .replace(/ P /g, ' l’')
    .replace(/ Y /g, ' l’')
    .replace(/ V /g, ' l’')
    .replace(/eh’ /g, 'ch’')
    .replace(/cbe/g, 'che')
    .replace(/Ohe/g, 'Che')
    .replace(/cbi/g, 'chi')
    .replace(/ alia /g, ' alla ')
    .replace(/ delia /g, ' della ')
    .replace(/ piu /g, ' più ')
    .replace(/Piu /g, 'Più ')
    .replace(/ gia /g, ' già ')
    .replace(/ r /g, ' l’')
    .replace(/\nr /g, '\nl’')
    .replace(/ air /g, ' all’')
    .replace(/ neir /g, ' nell’') 
    .replace(/ perche /g, ' perchè ')
    .replace(/ poiche /g, ' poichè ')
    .replace(/ cosi /g, ' così ')
    .replace(/ bai /g, ' hai ')
    .replace(/ ba /g, ' ha ')
    .replace(/ ne /g, ' nè ')
    .replace(/II/g, 'Il')
    .replace(/rrapaboe/g, 'rrapahoe')
    .replace(/wigwam/g, '\'\'wigwam\'\'')
    .replace(/indian-agent/g, '\'\'indian-agent\'\'')
    .replace(/Neil/g, 'Nell')
    .replace(/lP/g, 'll’')
    .replace(/’1/g, '’l')
    .replace(/ :/g, ': ')
    .replace(/([bcdfghlmnprstvzBCDFGHLMNPRSTV])’ /g, '$1’')
    .replace(/[(\[] /g, ' $1')
    .replace(/ \n/g, '\n')
    .replace(/-\n/g, '')
    .replace(/- \n/g, '')
    .replace(/ ,/g, ', ')
    .replace(/ ;/g, '; ')
    .replace(/ !/g, '! ')
    .replace(/ \?/g, '? ')
    .replace(/ \./g, '. ')
    .replace(/ :/g, ': ')
    .replace(/« /g, '«')
    .replace(/ »/g, '»')
    .replace(/\( /g, '(')
    .replace(/ \)/g, ')')
    .replace(/\t/g, ' ')
    .replace(/  /g, ' ')
    .replace(/\n— /g, '\n\n— ');
  }
}


//CORREZIONI PER I VICERÈ
function postOCRPersonaleVicere() {
  if (mw.config.get('wgPageName').indexOf("Pagina:I_Vicerè") != -1 && getPageQuality() == '1') {
        $('#wpTextbox1').val($('#wpTextbox1').val()
                                     .replace(/\n"(.*?)"/g, '\n― $1 ― ')
                                     .replace(/"(.*?)"/g, '«$1»')
                                     .replace(/  /g, ' ')
                                     .replace(/  /g, ' ')
                                     .replace(/ *― *\n/g, '\n')
                                     .replace(/«»/g, '')
                                     .replace(/\n"/g, '\n― ')
                                     .replace(/"/g, '')
                                     .replace(/é/g, 'è')
                                     .replace(/<nowiki \/>\s*/g, '')
                                     .replace(/badìa/g, 'badia')
                                     .replace(/ - /g, ' ― ')
        );
  }
}

//link per 5000 risultati
$('.mw-numlink[title="Mostra 500 risultati per pagina"]').each(function() {
	var newLink = $(this).clone();
	newLink.attr('href', newLink.attr('href').replace('limit=500', 'limit=5000'));
	newLink.attr('title', newLink.attr('title').replace('500', '5000'));
	newLink.html('5000');
	$(this).after(newLink).after(' | ');
});

//adapted from https://meta.wikimedia.org/wiki/User:Glaisher/autoPurge.js
/** When action=purge is reached, automatically purge the page and then redirect to the actual page.
 * Attempts to imitate the previous behavior for logged-in users.
 */
if ( mw.config.get( 'wgAction' ) === 'purge' ) {
	$('form[action$="action=purge"]').submit();
}

// segna in grigio le categorie di lavoro sporco vuote
$('.page-Categoria_Lavoro_sporco .CategoryTreeItem, .page-Categoria_Lavoro_sporco_su_Wikidata .CategoryTreeItem, .page-Speciale_CategorieMonitoraggio .mw-trackingcategories-name').each(function() { 
	if ($(this).find('span:not(.CategoryTreeEmptyBullet)').text() == '(vuota)') { 
		$(this).css('text-decoration', 'line-through').css('color', '#C0C0C0');
		$(this).find('a').css('color', '#C0C0C0');
	} 
});
if (mw.config.get('wgPageName') == 'Speciale:LintErrors') {
	var par = $('bdi:contains("(0 errori)")').parent('li');
	par.css('text-decoration', 'line-through').css('color', '#C0C0C0');
	par.find('a').css('color', '#C0C0C0');
}

if (mw.config.get('wgPageName').startsWith('Speciale:LintErrors')) {
	$('.mw-datatable').addClass('rownumber');
}

// purge sulle pagine Lint Errors
$('.mw-special-LintErrors .mw-specialpage-summary').prepend('<a href="#" id="purgeAll" class="btn blue" style="float: right;">Purge</a>');
$('#purgeAll').click(function() {
	$('.TablePager_col_title').each(function(i) {
		title = $(this).find('a:first').text();
		console.log('purge: ' + title);
		new mw.Api().post( { action: 'purge', titles: title } );
	});
});