Created
February 20, 2020 11:20
-
-
Save oddvalue/84977fa6a48149e9da9073562a2a37e7 to your computer and use it in GitHub Desktop.
Open telescope when you type "telescope"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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