Skip to content

Instantly share code, notes, and snippets.

@nikopol
Last active January 4, 2021 09:01
Show Gist options
  • Save nikopol/1121a9add75cc6fc20cf6ce1848e767b to your computer and use it in GitHub Desktop.
Save nikopol/1121a9add75cc6fc20cf6ce1848e767b to your computer and use it in GitHub Desktop.
happy new year!
(() => {
let p = 0;
const
ucb = p => new Promise(r => r(alert('happy new year!'))),
l = () => document.addEventListener('keydown', el),
cb = () => ucb(document.removeEventListener('keydown', el)).then(l),
k = [76,82,85,68,97,98],
co = [2,2,3,3,0,1,0,1,5,4],
el = e => {
p = k[co[p]] - e.key.charCodeAt(Math.min(e.key.length-1, 5)) ? 0 : ++p===10 ? cb()||0 : p;
return true;
};
l();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment