User:Enterprisey/massblock.js

// if( mw.config.get( "wgPageName" ) === "Special:BlankPage/mass-block" ) { $( "#mw-content-text" ).empty .append( "Usernames (one per line):" ) .append( $( " ", { "rows":"8", "cols":"100", "id":"mass-block-users" } ) ) .append( " " ) .append( "Reason (will also be used for edit summary on talk page): " ) .append( $( " ", { "type":"text", "length":"256", "id":"mass-block-reason" } ) ) .append( " " ) .append( "Talk page section name: " ) .append( $( " ", { "type":"text", "length":"256", "id":"mass-block-talk-header" } ) ) .append( " " ) .append( "Talk page message: " ) .append( $( " ", { "rows":"8", "cols":"100", "id":"mass-block-talk" } ) ) .append( " " ) .append( $( " " ).text( "Block all" ).click( function { mw.loader.using( [ "mediawiki.api" ], function {                var api = new mw.Api;                var reason = $( "#mass-block-reason" ).val;                var users = $( "#mass-block-users" ).val.split( '\n' );                var talkHeader = $( "#mass-block-talk-header" ).val;                var talkMessage = $( "#mass-block-talk" ).val;                users.forEach( function ( username ) { api.postWithToken( "csrf", {                       action: "block",                        user: username,                        expiry: "indefinite",                        reason: reason,                        anononly: true, // just because twinkle has it on                        nocreate: false,                        autoblock: false,                        noemail: false,                        allowusertalk: true                    } ).then( function  {                        console.log("Blocked " + username);                        return api.postWithToken( "csrf", { action: "edit", title: "User talk:" + username, section: "new", sectiontitle: talkHeader, text: talkMessage, summary: reason, } ).then( function{console.log("Notified " + username);} )                           .catch( function ( e ) { console.error( e ); } );                    }.bind( this ) ).catch( function ( e ) { console.error( e ); } ); } ) // end forEach callback           } ); // end mw.loader.using } ) ); // end button click handler } //