1

It annoys me that certain web sites intercept standard browser UI hotkeys.

I use Firefox and when I hit the forward slash key ('/'), I want to search the text in the current tab. I do not want the cursor to get focused in google's search box at the top of the page. Here's a typical offending page:

https://groups.google.com/forum/#!msg/vim_use/r3TdW9G9ms4/s-Jr3BpcnvUJ

I've tried some greasemonkey techniques that work on other sites, like installing my own addEventListener() for keyup, keydown and keypress as seen here, or replacing prototype.addEventListener() as seen here.

Here's some sample code where I try to nuke all key event listeners on all div elements using the latter technique:

// ==UserScript==
// @description Stop google groups from highjacking the keyboard
// @include     http://groups.google.com/*
// @include     https://groups.google.com/*
// @run-at      document-start
// @grant       unsafeWindow
// ==/UserScript==

realHTMLDivElementAddEventListener = unsafeWindow.HTMLDivElement.prototype.addEventListener;
unsafeWindow.HTMLDivElement.prototype.addEventListener = function(a,b,c) {
  if ( a == 'keydown' || a == 'keyup' || a == 'keypress' ) {
    console.log("zapped: " + a);
    console.log("zapped:  this is id: " + this.id);
    console.log("zapped:  this is cl: " + this.className);
  } else {
    realHTMLDivElementAddEventListener(a,b,c);
  }
}

This catches a few but let's hundreds of event listeners still get installed. Fireing my GM on "load" or "DOMContentLoaded" did not help things...

I'm actually not sure it's a DIV element that needs zapping (I've not been able to coax Firebug into breaking when I hit '/'), but I'm surprised that the code above fails to zap all attempts to add a key event listenver to a DIV.

Has google figured out a way to elude the power of Greasemonkey?

Community
  • 1
  • 1
T. Perkins
  • 13
  • 3

1 Answers1

0
// ==UserScript==
// @name         Google Groups Key Redemption
// @namespace    github.com/zanetu
// @version      0.1
// @description  Prevents Google Groups from intercepting browser hotkeys such as forward slash key. 
// @include      /^https?\:\/\/groups\.google\.com\//
// @author       zanetu
// @license      GPL version 2 or any later version; http://www.gnu.org/licenses/gpl-2.0.txt
// @grant        none
// @run-at       document-start
// ==/UserScript==

var ael = window.addEventListener
window.addEventListener = function(type) {'keypress' != type && ael.apply(this, arguments)}
zanetu
  • 3,740
  • 1
  • 21
  • 17
  • If I add `// @include /^https?\:\/\/www\.youtube\.com\//` to the above and then try http://www.youtube.com/watch?v=TllPrdbZ-VI, sadly, the above does not work. Can the above be enhanced to work with youtube as well? – T. Perkins Apr 26 '15 at 16:54
  • @T.Perkins [Firefox hotkeys seem not to be working well with Youtube](https://bugzilla.mozilla.org/show_bug.cgi?id=1158662), which I am not going to dig into. None the less, if you are a diehard Vim user, consider using [Vimperator](https://addons.mozilla.org/en-US/firefox/addon/vimperator/) add-on. – zanetu Apr 27 '15 at 05:27
  • Thanks for filing the Firefox bug @zanetu. I tested Vimperator, and it did prevent youtube from stealing the slash key, but it brought up its own search dialog (not the native "find bar" one). This gave me the idea that maybe I could write a little addon that could open the native dialog... For those interested, this little kludge of an addon fixes the slash key problem for youtube (and all other sites that I've tried): http://github.com/perkint/slashpreserver – T. Perkins Jun 12 '15 at 19:30