User:Infinite0694/Simple blocking tool.js

// $.when( mw.loader.using( [ "mediawiki.api", "mediawiki.util" ] ), $.ready ).then( function {    var MONTHS = mw.config.get( "wgMonthNames" ).slice( 1 ); // theirs starts with the empty string    var api = new mw.Api;    var IP_BLOCK_LENGTH = "31 hours";

function go( obj ) { obj.find( "span.mw-usertoollinks" ).each( function( idx, element ) {           $( element ).contents.last.before( " | ", $( "" ).attr( "href", "#" ) .text( "INF" ) .click( function {                        var username = $( this ).parent.get( 0 ).previousElementSibling.textContent;                        if( confirm( "Block " + username ) ) {                            var isAnon = $( this ).parent.get( 0 ).previousElementSibling.className.indexOf( "mw-anonuserlink" ) >= 0;                            new mw.Api.postWithToken( "csrf", { action: "block", user: username, expiry: isAnon ? "31 hours" : "never", reason: "sockpuppet", nocreate: "true", autoblock: "true", noemail: "true", } ).then( function { mw.notify( "Blocked " + username ); deliverBlockTemplate( username, isAnon ); } );                           return false;                        }                    } ) );        } ) // end .each } // end function go

mw.hook( "wikipage.content" ).add( function ( obj ) { go( obj ); } ); } ); // end $.when handler //