Hack #69. Remove Conflicting Keyboard Shortcuts

Remove annoying access keys from web pages that define conflicting shortcuts.

"Add an Access Bar with Keyboard Shortcuts" [Hack #68] introduced the concept of site-specific keyboard shortcuts (called access keys, after the attribute used to define them). Like Greasemonkey itself, access keys can be used for good or for evil. A malicious web page could redefine all available access keys to point to a link that tries to download a harmful executable or pop up an advertising window. Or a web publisher could—with the best of intentions—end up defining access keys that conflict with standard keyboard shortcuts in your browser.

Wikipedia, an otherwise excellent online encyclopedia, is such a site. It defines several access keys, including some (such as Alt-E) that conflict with the keyboard shortcuts for opening menus in the Firefox menu bar. This hack removes all access keys from a page to avoid the possibility of such conflicts.

The Code

This user script runs on all pages. It uses an XPath expression to find all the elements with an accesskey attribute, and then removes the attribute. This is enough to get Firefox to remove the associated keyboard shortcut from the link or form field.

Save the following user script as unaccesskey.user.js:

 // ==UserScript== // @name Remove AccessKeys // @namespace http://diveintomark.org/projects/greasemonkey/ // @description remove accesskey shortcuts from web pages // @include * // ==/UserScript== var ...

Get Greasemonkey Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.