MediaWiki:Gadget-SureSureSure.js

Da Semi del Verbo, l'enciclopedia dell'influenza del Vangelo sulla cultura

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.
/**
 * Aggiunge una richiesta di conferma al primo click di un rollback nella pagina e
 * consente a tutti i rollback successivi di partire all'istante come di consueto.
 * L'uso è configurabile a seconda di touch screen e dimensioni della finestra.
 *
 * @license [[WTFPL]] or [[GNU GPL]] or [[CC BY SA 3.0]] at your opinion
 * @author [[w:User:Valerio Bozzolan]] and contributors
 */

$( function () {
	var defaultOpts = {
		confirm: 'sicuro sicuro sicuro?',
		disablePatrolAjax: false,
		hasTouchScreen: undefined,
		maxScreenWidth: Infinity
	};

	window.sureSureSure = window.sureSureSure || {};

	var opts = $.extend( defaultOpts, window.sureSureSure );
	var isIOS = /iPad|iPhone|iPod/.test( navigator.platform ); // Safari iOS pre 13

	if (
		opts.maxScreenWidth < window.innerWidth ||
		opts.hasTouchScreen !== undefined &&
		opts.hasTouchScreen !== ( isIOS ? isIOS : navigator.maxTouchPoints > 0 )
	) {
		return;
	}

	mw.hook( 'wikipage.content' ).add( function () {
		$( '.mw-rollback-link a' ).click( function ( event ) {
			var yes = 'ok-guy-im-not-accidentally-clicking-this';
			if( !$( this ).hasClass( yes ) && !window.sureSureSure._yetConfirmed ) {
				var $t = $( this );
				$t.addClass( yes ).text( $t.text() + ": " + opts.confirm );
				event.preventDefault();
				window.sureSureSure._yetConfirmed = true;
			}
		} );
	} );

	if ( opts.disablePatrolAjax ) {
		mw.loader.using( 'mediawiki.misc-authed-curate' ).then( function () {
			$( '.patrollink[data-mw="interface"] a' ).off( 'click' );
		} );
	}
} );