User:Rjd0060/block-notice.js

// Alexander Monk, 2014-08-05 function buildGBlockForm { var $durationInput = $( ' ' ) .attr( 'name', 'gblockDuration' ) .attr( 'id', 'gblockDuration' ) .attr( 'type', 'text' ), $reasonInput = $( ' ' ) .attr( 'name', 'gblockReason' ) .attr( 'id', 'gblockReason' ) .attr( 'type', 'text' ), $form = $( ' ' ) .css( 'font-size', '10pt' ) .append( $( ' ' ).text( 'GBlock data' ), $( ' ' ).append( $( ' ' ).append( $( ' ' ).text( 'Duration:' ), $( ' ' ).append( $durationInput ) ), $( ' ' ).append( $( ' ' ).text( 'Reason:' ), $( ' ' ).append( $reasonInput ) ), $( ' ' ).append( $( ' ' ).append( $( ' ' ) .attr( 'type', 'submit' ) ) ) ) ); $form.submit( function { var text = "\{\{subst:User:Rjd0060/blocknotice\|" + $reasonInput.val + "\|" + $durationInput.val + "\}\}"; mw.loader.using( 'mediawiki.api.edit', function  { new mw.Api.postWithEditToken( { action: 'edit', minor: 'true', title: mw.config.get( 'wgPageName' ), appendtext: text, summary: "You have been blocked from editing." } ).done( function { window.location.reload; } ).fail( function ( code, result ) { $( '#contentSub' ).html( "Failure! " + code + " " + result ); } ); } ); return false; } ); $( '#contentSub' ).html( $form ); }; $( function { if ( mw.config.get( 'wgNamespaceNumber' ) == 3 ) { mw.util.addPortletLink( 'p-tb', 'javascript:buildGBlockForm', 'GBlock', 't-gblock' ); } } );