User:Technical 13/SandBox/forceSummary.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
( function ( mw, $ ) {
	if ( mw.user.options.get( 'forceeditsummary' ) === '1' ) {
		$( 'input#wpSave' ).click( function ( e ) {console.warn( 'clicked save page' );
			e.preventDefault();console.warn( 'prevented default' );
			$( function() {
				if ( $( '#wpSummary' ).val() === '' ) {console.warn( 'summary empty' );
					var saveAnyway = confirm( 'Save without edit summary?' );
					if ( saveAnyway ) {console.warn( 'saveAnyway was true, saving' );
						$( '#editform' ).submit();
					} else {console.warn( 'saveAnyway was false, returning' );
						return false;
					}
				} else {console.warn( 'summary not empty, saving' );
					$( '#editform' ).submit();
				}
			} );
			$( '#wpSummary' ).focus();
		} );
	}
} ( mediaWiki, jQuery ) );