Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Konami Code detector written in effection
import { run } from 'effection';
import { once } from '@effection/events';
run(function*() {
yield konamiCodeEntered();
alert('99 lives!');
});
function * konamiCodeEntered() {
while (true) {
if (yield nextKeyIs('ArrowUp')) {
if (yield nextKeyIs('ArrowUp')) {
if (yield nextKeyIs('ArrowDown')) {
if (yield nextKeyIs('ArrowDown')) {
if (yield nextKeyIs('ArrowLeft')) {
if (yield nextKeyIs('ArrowRight')) {
if (yield nextKeyIs('ArrowLeft')) {
if (yield nextKeyIs('ArrowRight')) {
if (yield nextKeyIs('b')) {
if (yield nextKeyIs('a')) {
if (yield nextKeyIs('b')) {
if (yield nextKeyIs('a')) {
return;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
function* nextKeyIs(key: string) {
let [event]: [KeyboardEvent] = yield once(document, 'keydown');
return event.key === key
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment