User:MacFan4000/cvtReasons.js

// /* * Script designed to add CVT specific deletion and block reasons on wikis. * Based heavily off https://meta.wikimedia.org/w/index.php?title=User:Snowolf/GS_delete.js */

$( document ).ready( function {	'use strict';

if ( mw.config.get( 'wgAction' ) !== 'protect' && mw.config.get( 'wgAction' ) !== 'delete' && mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Block' && mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'CentralAuth' ) { return; }

// Creates the html for a containing the given reasons function constructOptgroup( reasons ) { var html = '';

for ( var i = 0; i<reasons.length; i++ ) { html += mw.html.element( 'option', { 'value' : reasons[i] }, reasons[i] ); }		html += ' ';

return html; }

// Reasons for both delete and block var additionalReasons = [ "Spam (CVT action)", "Vandalism (CVT action)", ];	// Reasons for protect only var additionalProtect = additionalReasons;/*.concat( [			Not sure we have any of these.		] );*/ // Reasons for delete only var additionalDelete = additionalReasons;/*.concat( [			Not sure we have any of these.		] );*/ // Reasons for blocks only var additionalBlock = additionalReasons.concat( [			"Intimidating behaviour/harassment (CVT action)",			"Cross-wiki issues (CVT action)",		] );

if ( mw.config.get( 'wgAction' ) === 'delete' ) { // Append reasons to action=delete $( '#wpDeleteReasonList' ).append( constructOptgroup( additionalDelete ) ); }	else if ( mw.config.get( 'wgAction' ) === 'protect' ) { // Append reasons to action=protect $( '#wpProtectReasonSelection' ).append( constructOptgroup( additionalProtect ) ); }	else if ( mw.config.get( 'wgAction' ) === 'setglobalaccountstatus' ) { // Append reasons to action=setglobalaccountstatus $( '#wpProtectReasonSelection' ).append( constructOptgroup( additionalBlock ) ); }	else { // Special:Block $( '#mw-input-wpReason' ).append( constructOptgroup( additionalBlock ) ); // Unselect the block reason and put it into the "Other:" field $( 'form input[type=submit]' ).click( function {			var blockReason = '',				$reasonSelect = $( '#mw-input-wpReason' ),				$reasonOther = $( '#mw-input-wpReason-other' );

if ( $reasonSelect.val === 'other' ) { return; }

blockReason = $reasonSelect.val; if ( blockReason && $reasonOther.val ) { blockReason += ': '; }			blockReason += $reasonOther.val;

$reasonOther.val( blockReason ); $reasonSelect.val( 'other' ); } );	} } );

//