User:Samuele2002/Gs action.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// [[m:User:Wim b]]
// Button delete's page
//###########################################################################

// Clear
mw.loader.using('oojs-ui').then(function () {

	if( mw.config.get('wgAction') === 'delete' && mw.config.get( 'wgUserGroups' ).indexOf( 'sysop' ) == -1 ) {
	
		var buttonClear = new OO.ui.ButtonWidget( {
			label: 'Pulisci motivazione',
			flags: [
				'destructive'
			]
		});    
	
		$('#wpConfirmB').parent().append( buttonClear.$element );
		buttonClear.$element.click(function () {
			$('#wpReason').val('');
			$('#wpReason').focus();
		});
	
	
	// GS Action
		var buttonInsert = new OO.ui.ButtonWidget( {
			label: 'Global sysop Action',
			target: '_blank',
		flags: [
			'primary',
			'progressive'
		]
		});    
	
		$('#wpConfirmB').parent().append( buttonInsert.$element );
		buttonInsert.$element.click(function () {
			Value = $('#wpReason').val();
			append = $('#wpReason').val( Value + ' ([[m:Global sysop|Global sysop]] Action)');
		});
		
	} 
}); // end delete button
	
	// Block page
	//###########################################################################
	$( function () {
	var CanonicalSpecialPageName = mw.config.get('CanonicalSpecialPageName');
	if( CanonicalSpecialPageName == 'Block' && mw.config.get( 'wgUserGroups' ).indexOf( 'sysop' ) == -1 ) {
	
			var GScheckbox = new OO.ui.CheckboxInputWidget( {
				value: 'Gs Action',
				inputId: 'Gs',
				selected: true
			} );
	 
	// Create a fieldset layout with fields for each checkbox.
		var fieldset = new OO.ui.FieldLayout( GScheckbox, { label: 'Global sysop Action', align: 'inline' } );
	
			$('#ooui-php-17').before( fieldset.$element.css('font-weight', 'bold'));   
	
			$('button[type="submit"]').click(function () {
				if($('input#Gs').prop( 'checked' ) ) {
					var Value = $('input[name="wpReason-other"]').val();
					var GSString = /\(\[\[m:Global sysop\|Global sysop\]\] Action\)/;
	
					if(GSString.test(Value)) { } else {
						$('input[name="wpReason-other"]').val( Value + ' ([[m:Global sysop|Global sysop]] Action)');
					}
				}
			});
	
		} 
	});// end block page