Created
May 27, 2012 03:06
-
-
Save jataro/2799464 to your computer and use it in GitHub Desktop.
Chrome Userscript - Shift+Enter New Window Blocker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on Chrome 18