public
Created

Chrome Userscript - Shift+Enter New Window Blocker

  • Download Gist
shiftenter_blocker.user.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// ==UserScript==
// @name Chrome Shift+Enter New Window Blocker
// @namespace http://www.joetotaro.net
// @description Stops Chrome from opening a new window when you are entering a password and press SHIFT+ENTER. Instead submits the login form.
// @copyright Joe Totaro
// @license MIT License; http://www.opensource.org/licenses/mit-license.php
// @include *
// ==/UserScript==
 
 
function supressShiftEnter(event){
//shift enter is pressed
if(event.keyCode == 13 && event.shiftKey){
var form = event.srcElement.form;
//try to submit the form
try{
if(typeof form.submit == 'function')
form.submit();
else
form.submit.click();
}
finally{
return false;
}
}
return true;
}
 
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++){
if (inputs[i].type == 'password'){
inputs[i].onkeypress = supressShiftEnter;
}
}

Tested on Chrome 18

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.