Skip to content

Instantly share code, notes, and snippets.

@abuduba
Last active May 15, 2020 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abuduba/90e8e0e9f3fe5479d9a49a52afbe04e2 to your computer and use it in GitHub Desktop.
Save abuduba/90e8e0e9f3fe5479d9a49a52afbe04e2 to your computer and use it in GitHub Desktop.
import { createContext } from './hotkeys';
const c = createContext();
// Alerts when "no way" is typed in.
c.register('n o space w a y', () => {
alert('Yes way!');
});
/*
It replaces the native search behaviour when pressing ctrl+f
Note, the callback gets the event from the last key,
that is matched in the given sequence
*/
c.register('ctrl+f', (event) => {
// prevent the native search behavior
event.preventDefault();
const value = prompt('What you are looking for?');
window.location.href = `https://www.google.com/?q=${value}`;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment