Skip to content

Instantly share code, notes, and snippets.

@bhb
Created April 20, 2009 18:48
Show Gist options
  • Save bhb/98658 to your computer and use it in GitHub Desktop.
Save bhb/98658 to your computer and use it in GitHub Desktop.
// This is a slightly altered version of the script at
// http://userscripts.org/scripts/show/43545
// I simply replaced
// 'w'.charCodeAt(0)
// with
// 23
document.addEventListener('keypress', function(event){
var target = event.target;
if (event.ctrlKey && event.charCode == 23
&& (/textarea/i.test(target.nodeName)
|| (/input/i.test(target.nodeName)
&& /text|password/.test(target.type))))
{
event.preventDefault();
var position = target.selectionStart;
var rOffset = target.value.length - position;
if (position != target.selectionEnd) return;
target.value =
target.value.substring(0, position - 1).
replace(/[^ \n\r`~!@#$%^&*()_+-=\[\]{}\\|\/;:'",.<>\?]+$/, '')
+ target.value.substring(position);
target.selectionEnd = target.selectionStart = target.value.length - rOffset;
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment