1
0
mirror of https://github.com/hexolan/konami-code-snippets.git synced 2026-05-20 11:39:22 +01:00

feat: add base snippet

Written when reworking a version of my dev landing site (should be
`O(1)`).
This commit is contained in:
2026-04-03 17:17:01 +01:00
parent e30ca93f3d
commit b7bce657c2
2 changed files with 48 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
// NOTE: not using deprecated `keyCode` attribute
const keySequence = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a"];
let sequenceStep = 0;
function callbackFunc() {
}
// TODO: as func to pass to `keydown` listener
document.addEventListener("keydown", function (e) {
console.log(e)
if (keySequence[sequenceStep] === e.key) {
sequenceStep += 1;
if (sequenceStep === keySequence.length) {
sequenceStep = 0;
callbackFunc();
}
} else {
sequenceStep = 0;
}
});