Skip to content

Instantly share code, notes, and snippets.

@oddvalue
Created February 20, 2020 11:20
Show Gist options
  • Save oddvalue/84977fa6a48149e9da9073562a2a37e7 to your computer and use it in GitHub Desktop.
Save oddvalue/84977fa6a48149e9da9073562a2a37e7 to your computer and use it in GitHub Desktop.
Open telescope when you type "telescope"
function openInNewTab(url) {
const win = window.open(url, '_blank');
win.focus();
}
const pattern = ['t', 'e', 'l', 'e', 's', 'c', 'o', 'p', 'e'];
let current = 0;
const keyHandler = (event) => {
// If the key isn't in the pattern, or isn't the current key in the pattern, reset
if (pattern.indexOf(event.key) < 0 || event.key !== pattern[current]) {
current = 0;
return;
}
// Update how much of the pattern is complete
current++;
// If complete, alert and reset
if (pattern.length === current) {
current = 0;
openInNewTab('/telescope');
}
};
// Listen for keydown events
document.addEventListener('keydown', keyHandler, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment