Skip to content

Instantly share code, notes, and snippets.

@julfers
Last active February 28, 2020 18:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julfers/85fdae998ad855de17d2326e1c141cac to your computer and use it in GitHub Desktop.
Save julfers/85fdae998ad855de17d2326e1c141cac to your computer and use it in GitHub Desktop.
/*
Save the slash key
##################
Greasemonkey script to prevent sites from hijacking Firefox's slash
key shortcut.
Source: https://gist.github.com/julfers/85fdae998ad855de17d2326e1c141cac
Install
*******
1. Install Greasemonkey from
https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
2. Click Github's "raw" link to install this script
See also
********
https://keyboard-savior-xtreme.readthedocs.io/
https://superuser.com/a/595885
https://stackoverflow.com/a/16459436
https://github.com/perkint/slashpreserver
Unlicense
*********
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
// ==UserScript==
// @name Save the slash key
// @namespace http://josiahulfers.com/saveslash
// @description Stop sites hijacking Firefox's slash key shortcut
// @run-at document-start
// @include http://tools.android.com/*
// @include https://*.android.com/*
// ^ slash-breaker on developer.android.com is buggy
// (sometimes doesn't hijack the key)
// @include https://bitbucket.org/*
// @include https://docs.djangoproject.com/*
// @include https://trello.com/*
// @include https://*.google.com/*
// @include https://www.youtube.com/
// @version 5
// @grant none
// @updateURL https://gist.github.com/julfers/85fdae998ad855de17d2326e1c141cac/raw
// ==/UserScript==
var saveSlash = function (keyEvent) {
if (keyEvent.key === '/') {
// Would ideally allow propagation if the target is editable, such
// as <input>, but, in practice, this hasn't been a problem.
keyEvent.stopImmediatePropagation()
}
}
window.addEventListener('keydown', saveSlash, true)
window.addEventListener('keypress', saveSlash, true)
window.addEventListener('keyup', saveSlash, true)
@julfers
Copy link
Author

julfers commented Feb 21, 2020

@racuna I'm sorry I didn't see your comment two years ago!

I would use if (keyEvent.ctrlKey && /^k$/i.test(keyEvent.key)). The case-insensitive regex makes it match whether you have capslock on or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment