Usuário:Editor D.S/improveVandalBlock.js

Origem: Wikipédia, a enciclopédia livre.

Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Internet Explorer / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
/**
 * @author [[w:pt:User:!Silent]]
 * @date 13/feb/2017
 * @update 06/out/2017
 */
/* jshint laxbreak:true, expr:true */
/* global mediaWiki, jQuery */

( function( mw, $ ) {
'use strict';

mw.messages.set( {
	'ivb-buttonName-0': 'vandalismo',
	'ivb-buttonName-1': 'tentativa',
	'ivb-blocking': 'Bloqueando o vândalo...',
	'ivb-reason-0': 'Vandalismo [[Wikipédia:Vandalismo|contumaz]]',
	'ivb-reason-1': 'Tentativa recente de [[WP:VAN|vandalismo]] frustrada por [[WP:FE|filtro]]',
	'ivb-notifying': 'Notificando o vândalo...',
	'ivb-sectionTitle': 'Notificação de bloqueio',
	'ivb-duration': 'um dia',
	'ivb-summary': 'Notificação de bloqueio usando um [[User:!Silent/improveVandalBlock.js|script]]',
	'ivb-success': 'O usuário "$1" foi bloqueado e notificado com sucesso.'
} );

var ivb = {
	alreadyBlocked: false
};

ivb.message = function ( /*name[, $1[, $2[, ... ]]]*/ ) {
	return mw.message.apply( this, arguments ).plain();
};


ivb.automatizeCheckOptions = function () {
/*	$( 'span[role="combobox"] .oo-ui-labelElement-label' ).eq( 0 ).html( '1 dia' );
	$( '#oojsui-10' )
		.addClass( 'oo-ui-optionWidget-selected oo-ui-optionWidget-highlighted' )
		.attr( 'aria-selected', 'true' );
	$( 'input[name="wpExpiry-other"]' ).hide();
*/
	if ( mw.util.isIPAddress( $( 'input[name="wpTarget"]' ).val() ) ) {
		$( 'input[name="wpDisableEmail"]' ).prop( 'checked', true );
		$( 'input[name="wpDisableUTEdit"]' ).prop( 'checked', true );
	}
};

ivb.instablock = function () {
	var blockType, $placement,
		type = !!mw.util.getParamValue( 'diff' ) ? 0 : 1,
		userNameBlocked = $( '.mw-autocomplete-user' ).val() || $( '.mw-userlink bdi' ).eq( type ? 0 : 1 ).text();

	if ( !mw.util.isIPAddress( userNameBlocked ) )
		return;

	if ( !!$( '.mw-abuselog-details' ).length ) {
		$placement = $( '.mw-usertoollinks a:last' );
	} else if ( !!mw.util.getParamValue( 'diff' ) ) {
		$placement = $( '#mw-diff-ntitle2 .mw-usertoollinks a:last' );
	} else {
		$placement = $( '#contentSub a' ).eq( mw.util.isIPAddress( userNameBlocked ) ? 1 : 2 );
	}

	$placement.after( ' [<a class="ivb-instablock" style="cursor: pointer;" type="' + type + '">' + ivb.message( 'ivb-buttonName-' + type ) + '</a> | <a class="ivb-instablock" style="cursor: pointer;" type="' + ( +!type ) + '">' + ivb.message( 'ivb-buttonName-' + ( +!type ) ) + '</a>]' );

	$( '.ivb-instablock' ).click( function() {
		if ( ivb.alreadyBlocked ) {
			return;
		}

		ivb.alreadyBlocked = true;
		blockType = $( this ).attr( 'type' );
		mw.notify( ivb.message( 'ivb-blocking' ) );

		$.post( mw.util.wikiScript( 'api' ), {
			action: 'block',
			user: userNameBlocked,
			token: mw.user.tokens.get( 'csrfToken' ),
			expiry: '1 day',
			reason: ivb.message( 'ivb-reason-' + blockType ),
			autoblock: 1,
			noemail: 1,
			nocreate: 1
		} ).done( function() {
			mw.notify( ivb.message( 'ivb-notifying' ) );

			( new mw.Api() ).editPage( {
				title: 'User talk:' + userNameBlocked,
				section: 'new',
				watchlist: 'preferences',
				sectiontitle: ivb.message( 'ivb-sectionTitle' ),
				text: '{{subst:Bloqueado|1=' + ivb.message( 'ivb-duration' ) + '|2=' + ivb.message( 'ivb-reason-' + blockType ) + '.}' + '} ~~' + '~~',
				summary: ivb.message( 'ivb-summary' ),
				done: function() {
					mw.notify( ivb.message( 'ivb-success', userNameBlocked ) );
				}
			} );
		} );
	} );
};

if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Block' && !$( '.error' ).length ) {
	$( ivb.automatizeCheckOptions );
}

if ( !!$( '.mw-abuselog-details' ).length || !!mw.util.getParamValue( 'diff' ) || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Contributions' ) {
	$( ivb.instablock );
}
}( mediaWiki, jQuery ) );

// [[Categoria:!Código-fonte de scripts|Botões de bloqueio imediato contra vândalos]]