Utente:Wim b/common.js

Da Wikizionario, il dizionario a contenuto aperto.

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.
/*Orologio*/
mw.loader.load('//it.wikipedia.org/w/index.php?title=MediaWiki:Gadget-Orologio.js&action=raw&ctype=text/javascript');

/*Contributi bot*/
mw.loader.using('mediawiki.util').then(function () {
mw.util.addPortletLink('p-navigation', '/wiki/Speciale:Contributi/Wim_bot', 'Contributi Wim bot', 'n-navbot');
});

/* Menù personalizzati */
importScript( 'Utente:Wim_b/ShortcutsMenu.js' );

/* Monobook Admin */
importScript( 'Utente:Wim_b/Admin/Global.js');

/* Configurazione strumenti extra */

function shortcutsInit ()
{ 
shortcutsAddLink ( 'Monobook admin', 'Utente:Wim_b/Admin.js' );
shortcutsAddLink ( 'Monobook admin (globale)', 'Utente:Wim_b/Admin/Global.js' );
shortcutsAddLink ( 'Controllo vandalismi', 'Utente:Wim b/Controllo vandalismi' );
shortcutsAddLink ( 'trasferimenti', 'w:Wikipedia:Proposte di trasferimento/Wikizionario' );

shortcutsStartSection ('Utilità');

shortcutsAddLink ( 'RC filtrate (verificate)', 'Speciale:UltimeModifiche/100,hidepatrolled' );
shortcutsAddLink ( 'RC filtrate (anonimi)', 'Special:Recentchanges/100,hideliu,hidepatrolled' );
shortcutsAddLink ( 'Fondo Bar', 'Wikizionario:Bar#footer' );
shortcutsAddLink ( 'switch lang', 'Wikizionario:switch_lang' );

shortcutsStartSection ('Admin');

shortcutsAddLink ( 'Nuovi utenti', 'Speciale:Registri/newusers' );
shortcutsAddLink ( 'AbuseFilter', 'Speciale:FiltroAntiAbusi' );
shortcutsAddLink ( 'Titoli bloccati', 'Speciale:Protectedtitles' );

}

// CRiteri aggiuntivi per MassDelete 
function AddMotivazioniPersonali ()
{
		AltreMotivazioniSemplici('Personali','Discussione utente anonimo scaduta');
		AltreMotivazioniSemplici('Personali','Vandalismo');
		AltreMotivazioniSemplici('Personali','Nessun riscontro');
		AltreMotivazioniSemplici('Personali','Voce enciclopedica: non adatta a Wikizionario');
		AltreMotivazioniSemplici('Personali','Come da richiesta dell\'utente a cui fa riferimento la pagina');
		AltreMotivazioni('AltreRagioni','Test, per favore usa la [[Project:Sandbox|sandbox]] (please use the [[Project:Sandbox|sandbox]])','Test');
}

//================== Script per LintErors ==================
var myLintHints = { };
myLintHints.rooms = "*";
mw.hook( "lintHint.config" ).fire( myLintHints );
mw.loader.load( "https://en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/lintHint/d.js&action=raw&bcache=1&maxage=86400&ctype=text/javascript" );

//================== Script per link rossi ==================
$(document).ready( function () {
    // Remove redlinks if they exist upon pageload
    redlinks_removeall();
});
$(function($) {
	mw.loader.using( ['mediawiki.util'] ).then( function () {
		var portletlink = mw.util.addPortletLink('p-tb', '#', 'Remove redlinks');
		$(portletlink).click( function(e) {
			e.preventDefault();
			// Default parameters, and begin script on regular view of article
			var loc = window.location.href;
			var redlinks; var i;
			
			// Gather all redlinks with class "new"
			redlinks = [];
			var a = document.getElementsByTagName('a');
			for (i = 0; i < a.length; i++) {
				if (a[i].getAttribute('class') == "new") {
					redlinks[redlinks.length] = a[i].href.replace('https://it.wiktionary.org/w/index.php?title=','').replace('&action=edit&redlink=1','');
					redlinks[redlinks.length-1] = redlinks[redlinks.length-1].replace(/_/g,' ');
					redlinks[redlinks.length-1] = decodeURIComponent(redlinks[redlinks.length-1]);
				}
			}
			
			// Save all redlinks
			if (redlinks.length > 0) {
				localStorage.redlinks = JSON.stringify(redlinks);
				
				// If we are in the edit page, then remove redlinks automatically; if we are on the reading page, then go to the edit page
				if (window.location.href.indexOf('action') >= 0) redlinks_removeall();
				else window.location = window.location.href.substr(0, window.location.href.indexOf('#'))+"?action=edit";
			} else {
				alert('No redlinks!');
			}
		});
	});
});

function redlinks_removeall() {
	// Automatic removal of redlinks when stored.
    if (localStorage.redlinks !== "" && localStorage.redlinks !== undefined) {
		// Gather saved redlinks
		var redlinks = JSON.parse(localStorage.redlinks);
		
		// Regular expression to escape special characters
		var totalredlinks = 0;
		RegExp.quote = function(str) { return str.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); };
		
		var wpTextbox1 = document.getElementById('wpTextbox1');
		for (i = 0; i < redlinks.length; i++) {
			// Regular expression for piped links and direct links
			var reglink1 = new RegExp('\\[\\[\\s*('+RegExp.quote(redlinks[i]).replace(/\s/g, "[\\s\\_]*")+')\\s*\\|\\s*([^\\]]*)\\s*\\]\\]','gi');
			var reglink2 = new RegExp('\\[\\[\\s*('+RegExp.quote(redlinks[i]).replace(/\s/g, "[\\s\\_]*")+')\\s*\\]\\]','gi');
			
			// Add total number of matches for both
			if (wpTextbox1.value.match(reglink1) !== null) totalredlinks += wpTextbox1.value.match(reglink1).length;
			if (wpTextbox1.value.match(reglink2) !== null) totalredlinks += wpTextbox1.value.match(reglink2).length; // Includes categories
			
			// Remove category rather than simply convert it to unlinked text
			if (redlinks[i].substr(0,9) == "Category:") {
				var reglink3 = new RegExp('\\[\\[\\s*('+RegExp.quote(redlinks[i])+')\\s*\\]\\]\\n','gi');
				wpTextbox1.value = wpTextbox1.value.replace(reglink3,"");
			}
			
			// Remove redlinks and convert to unlinked text
			wpTextbox1.value = wpTextbox1.value.replace(reglink1,"$2");
			wpTextbox1.value = wpTextbox1.value.replace(reglink2,"$1");
		}
		
		// Alert for summary of removed redlinks; total in edit summary
		if (totalredlinks > 0) {
			document.getElementById('wpSummary').value += "Removed "+totalredlinks+" redlink"+(totalredlinks==1?"":"s")+" via [[en:w:User:Alex 21/script-redlinks|script]].";
			alert("Automatically removed "+totalredlinks+" redlink"+(totalredlinks==1?"":"s")+"!");
		} else {
			// Redlinks were seen in the article but none were found in the wikicode - check the nevigational boxes for these redlinks
			alert('No redlinks in the article! (Check transcluded templates and the navigational boxes.)');
		}
		
		// Remove the template(s)
		wpTextbox1.value = wpTextbox1.value.replace(/\{\{[Cc]leanup-?\s*[Rr]ed\s*[Ll]inks?[^\}]*\}\}/g, "");
		wpTextbox1.value = wpTextbox1.value.replace(/\{\{[Rr]ed\s*links?[^\}]*\}\}/g, "");
		wpTextbox1.value = wpTextbox1.value.replace(/\{\{[Tt]oo many red links[^\}]*\}\}/g, "");
		
		// Clear all saved redlinks
		localStorage.redlinks = '';
	}
}