Utente:Ricordisamoa/RimuoviTemplateO.js

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca

Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.


Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.

/* <nowiki>
 * RimuoviTemplateO.js di [[Utente:Ricordisamoa]]
 * usa jQuery & Ajax
 * sostituisce "rimuovi" nel Template:O con un link per rimuovere il template rapidamente
*/
/* global $, mw */
$( document ).ready( function () {
	'use strict';
	if ( mw.config.get( 'wgAction' ) === 'view' &&
	mw.config.get( 'wgPageName' ) !== 'Utente:Ricordisamoa/RimuoviTemplateO' &&
	mw.config.get( 'wgNamespaceNumber' ) !== 10 ) {
		$( 'div' ).each( function () {
			$( this )
			.contents()
			.filter( function () {
				return this.nodeType === 3;
			} )
			.each( function () {
				var node,
				parts = [ 'almeno uno pertinente e non generico e ', 'rimuovi', ' l\'avviso' ],
				find = this.textContent.indexOf( parts.join( '' ) );
				if ( find !== -1 ) {
					node = this.splitText( find + parts[ 0 ].length );
					$( node.splitText( parts[ 1 ].length ).previousSibling )
					.wrap( '<a>' ).parent()
					.attr( {
						href: '#',
						title: 'Rimuovi questo avviso automaticamente'
					} )
					.click( function ( event ) {
						var $container;
						event.preventDefault();
						$container = $( this ).parents( 'table.avviso' );
						$( this ).replaceWith( $( this ).text() );
						mw.loader.using( 'jquery.spinner', function () {
							var fail;
							$container
							.find( 'td.avviso-immagine img' ).slideUp( {}, function () {
								$( this ).parents( 'td' ).hide();
							} )
							.parents( 'td' )
							.next( 'td.avviso-testo' )
							.animate( {
								opacity: 0.5
							}, 500 )
							.append( $.createSpinner( {
								size: 'large',
								type: 'block'
							} ) );
							fail = function () {
								mw.notify( 'RimuoviTemplateO.js:\nla richiesta ajax è fallita.' );
								$container
								.find( 'td.avviso-immagine' ).show()
								.find( 'img' ).stop().show().end()
								.next( 'td.avviso-testo' )
								.stop().css( 'opacity', 1 )
								.find( '.mw-spinner' ).remove();
							};
							$.get(
								mw.util.wikiScript(),
								{
									title: mw.config.get( 'wgPageName' ),
									action: 'raw'
								}
							)
							.done( function ( d ) {
								new mw.Api().postWithToken( 'edit', {
									action: 'edit',
									format: 'json',
									text: d.replace( /\{\{o(\|[^\{\}]+)*\}\}\n?/i, '' ),
									title: mw.config.get( 'wgPageName' ),
									summary: 'rimozione [[Utente:Ricordisamoa/RimuoviTemplateO|automatica]] di {{[[Template:O|O]]}}' +
									' (controlla i [[Speciale:PuntanoQui/' + mw.config.get( 'wgPageName' ) + '|collegamenti in entrata]])'
								} )
								.done( function () {
									$container.animate( {
										opacity: 0
									}, 500, function () {
										$( this ).remove();
									} );
								} )
								.fail( fail );
							} )
							.fail( fail );
						} );
					} );
					return false;
				}
			} );
		} );
	}
} );