User:Zhaofeng Li/SummaryGuard.js

/*	SummaryGuard * Disables the Save page button if no edit summary is entered * Displays the length of the edit summary above the box * Warns about an over-lengthed summary

// ==UserScript== // @name       SummaryGuard // @description Forces you to enter an edit summary when editing English Wikipedia. // @namespace  https://en.wikipedia.org/wiki/User:Zhaofeng_Li // @include    *://en.wikipedia.org/*action=edit* // @version    1 // @grant      none // ==/UserScript==

$( document ).ready( function {	if ( $( '#editform' ).length ) { // only when editing		$( "#wpSummaryLabel" ).after( " " );		$( '#wpSummary' ).keyup( checkSummary );		checkSummary;	} } );

function checkSummary { var length = $( '#wpSummary' ).val.length; if ( length ) { // edit summary provided $( '#wpSave' ).removeAttr( "disabled"); // enable save button $( "#summaryGuard" ).text( "(" + length + "/255)" ); if ( length <= 100 ) { // okay $( "#summaryGuard" ).css( "color", "#a7d7bf" ); // green } else if ( length <= 150 ) { // a bit lengthy... $( "#summaryGuard" ).css( "color", "#f9c557" ); // orange } else { // that's too long... $( "#summaryGuard" ).css( "color", "#cc0000" ); // red }		} else { // nothing entered $( '#wpSave' ).attr( "disabled", "disabled" ); $( "#summaryGuard" ).text( "" ); } }