-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkonami.html
More file actions
43 lines (34 loc) · 1.33 KB
/
konami.html
File metadata and controls
43 lines (34 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html>
<head>
<title>Konami Code</title>
</head>
<body>
<h1>Konami Code</h1>
<script>
"use strict";
document.addEventListener("keyup", event => console.log(event.key));
const konamiSeq = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "Shift", "B", "A", "Enter"]; // for .addEventListener("keydown"...
// const konamiSeq = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "B", "A", "Shift", "Enter"]; // for .addEventListener("keyup"...
const userKonami = [];
let currentIndex = 0;
document.addEventListener("keyup", event => {
const key = event.key;
if (key === konamiSeq[currentIndex]) {
userKonami.push(key);
currentIndex++;
if (currentIndex === konamiSeq.length) {
alert("Konami Code Entered!");
// You can perform a specific action here when the Konami Code is entered.
currentIndex = 0;
userKonami.length = 0; // Clear the user's input
}
} else {
// Reset if the key doesn't match the current sequence
currentIndex = 0;
userKonami.length = 0; // Clear the user's input
}
});
</script>
</body>
</html>