Usuário:!Silent/instablockVandal.js: diferenças entre revisões

Origem: Wikipédia, a enciclopédia livre.
Conteúdo apagado Conteúdo adicionado
m Ajuste pra possibilitar (via console) que o script não exiba os botões quando se tratar de um usuário cadastrado
Atalho para o filtro de edições
Linha 16: Linha 16:
'ivb-confirm': 'Deseja realmente bloquear este editor?',
'ivb-confirm': 'Deseja realmente bloquear este editor?',
'ivb-reason-0': 'Vandalismo [[Wikipédia:Vandalismo|contumaz]]',
'ivb-reason-0': 'Vandalismo [[Wikipédia:Vandalismo|contumaz]]',
'ivb-reason-1': 'Tentativa recente de vandalismo frustrada por filtro',
'ivb-reason-1': 'Tentativa recente de vandalismo frustrada por [[WP:FE|filtro]]',
'ivb-notifying': 'Notificando o vândalo...',
'ivb-notifying': 'Notificando o vândalo...',
'ivb-sectionTitle': 'Notificação de bloqueio',
'ivb-sectionTitle': 'Notificação de bloqueio',

Revisão das 12h52min de 14 de abril de 2017

/**
 * @author [[w:pt:User:!Silent]]
 * @date 13/feb/2017
 * @update 25/mar/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-confirm': 'Deseja realmente bloquear este editor?',
	'ivb-reason-0': 'Vandalismo [[Wikipédia:Vandalismo|contumaz]]',
	'ivb-reason-1': 'Tentativa recente de 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 () {
	$( '#mw-input-wpExpiry option[value="1 day"]' ).attr( 'selected', true );

	if ( mw.util.isIPAddress( $( '#mw-bi-target' ).val() ) ) {
		$( '#mw-input-wpReason option[value="Vandalismo [[Wikipédia:Vandalismo|contumaz]]"]' ).prop( 'selected', true );
		$( '#mw-input-wpDisableEmail' ).prop( 'checked', true );
		$( '#mw-input-wpDisableUTEdit' ).prop( 'checked', true );
		$( '#mw-input-wpHardBlock' ).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 ) && !!localStorage[ 'ivp-ignoreRegisteredUsers' ] ) {
		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" type="' + type + '">' + ivb.message( 'ivb-buttonName-' + type ) + '</a> | <a class="ivb-instablock" type="' + ( +!type ) + '">' + ivb.message( 'ivb-buttonName-' + ( +!type ) ) + '</a>]' );

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

		if ( !!mw.util.getParamValue( 'diff' ) && !confirm( ivb.message( 'ivb-confirm' ) ) ) {
			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 ) );