Created
February 24, 2013 04:44
-
-
Save michaeltwofish/5022635 to your computer and use it in GitHub Desktop.
The two things I wanted to achieve were:
* Allow `delete` and `shift+delete` to navigate history if one of the pages happens to be a google search page. By default, google will hijack the keypress, regardless of focus, so you'll just delete in the search box.
* Allow link highlighting and navigation with the `Keyboard Navigation` extension. I th…
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 Google Behave | |
// @namespace http://twofishcreative.com | |
// @description Stops the Google search page hijacking useful key events. Based on Zimzat's Arrow Key Guard http://userscripts.org./scripts/show/88447 | |
// @match http://www.google.com/* | |
// @match https://www.google.com/* | |
// @match http://www.google.com.au/* | |
// @match https://www.google.com.au/* | |
// ==/UserScript== | |
/* Copyright (c) 2013 michaeltwofish | |
* | |
* This work is licensed under the Creative Commons Attribution 3.0 License. | |
* To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send | |
* a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA. | |
*/ | |
(function() { | |
var ESC_KEY_CODE = 27 | |
function googleBehave(event) { | |
if (typeof googleBehave.behaving == 'undefined') { | |
googleBehave.behaving = false; | |
} | |
if (event.keyCode == ESC_KEY_CODE) { | |
googleBehave.behaving = !googleBehave.behaving; | |
} | |
console.log('Behaving: ' + googleBehave.behaving); | |
if (googleBehave.behaving) { | |
console.log('Cancelled ' + event); | |
event.cancelBubble = true; | |
event.stopPropagation(); | |
// We're not doing preventDefault() because we still want the browser doing its thing. | |
// That's the entire point of this script. | |
return false; | |
} | |
} | |
window.addEventListener('keypress', googleBehave, true); | |
window.addEventListener('keydown', googleBehave, true); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment