User:Hasley/quick-vand-block.js

/* jshint esversion: 6 */ // forked from User:Enterprisey/quick-vand-block.js $.when( mw.loader.using( [ 'mediawiki.api', 'mediawiki.util' ] ), $.ready ).then( function {	function go( obj, name, config ) {		const namespace = mw.config.get( 'wgCanonicalSpecialPageName' );		obj.find( 'span.mw-usertoollinks' ).each( function ( idx, element ) { $( element ).contents.last.before( ' | ',				$( '' ).attr( 'href', '#' )					.text( name )					.click( function { let username; try { username = $( this ) .parent .get( 0 ) .previousElementSibling .textContent; } catch ( e ) { if ( e instanceof TypeError && namespace === 'Watchlist' ) { username = $( this ) .parents .siblings( '.mw-changeslist-line-inner-userLink' ) .find( '.mw-userlink' ) .text; } else { console.log( e ); }						}						username = username.trim; if ( confirm( `Block ${username}?` ) ) { let isAnon; try { isAnon = $( this ) .parent .get( 0 ) .previousElementSibling .className .indexOf( 'mw-anonuserlink' ) >= 0; } catch ( e ) { if ( e instanceof TypeError ) { const regex = /((\d{1,3}\.){3}\d{1,3}|([\da-f]{0,4}:){1,7}[\da-f]{0,4})/gi; isAnon = $.inArray( namespace, [ 'CheckUser', 'Watchlist' ] ) !== -1 && regex.test( username ); } else { console.log( e ); }							}							new mw.Api.postWithToken( 'csrf', {								action: 'block',								user: username,								expiry: isAnon ? config.ln.ip : config.ln.registered,								reason: config.reason,								reblock: config.reblock,								nocreate: true,								autoblock: true,								anononly: true,								allowusertalk: isAnon,								noemail: !isAnon							} ).then( function {								mw.notify( `${username} has been blocked.` );							} ); return false; }					} ) );		} );	}	const blockConfig = {		filterVd: {			reason: 'Vandalismo/Vandalismo frustrado por el filtro antiabusos',			ln: { ip: '31 hours', registered: 'never' },			reblock: false		},		lta: {			reason: 'Abuso a largo plazo (LTA)',			ln: { ip: '2 years', registered: 'never' },			reblock: true		}	};	mw.hook( 'wikipage.content' ).add( function ( obj ) { go( obj, '31h', blockConfig.filterVd ); go( obj, 'LTA', blockConfig.lta ); } ); } );