User:Zhaofeng Li/SummaryGuard.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Zhaofeng Li/SummaryGuard. |
/*
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( "<span id='summaryGuard' style='margin-left:5px;'></span>" );
$( '#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( "" );
}
}