User:Buehl106/Simple blocking tool.js

/** * Copy from w:User:Enterprisey/quick-vand-block.js * User:Enterprisey/quick-vand-block.js * w:Special:PermaLink/958655955 * @license * @author w:en:User:Enterprisey, @editInfinite0694 */ // $.when( mw.loader.using( [ "mediawiki.api", "mediawiki.util" ] ), $.ready ).then( function {

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( "無期限" ) .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;                            api.postWithToken( "csrf", { action: "block", user: username, expiry: isAnon ? IP_BLOCK_LENGTH : "never", reason: "Vandalism", nocreate: "true", autoblock: "true", noemail: "true" } ).then( function { mw.notify( username + "をブロックしました"); } );                           return false;                        }                    } ) );        } ) // end .each } // end function go

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