forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex-jds.html
More file actions
42 lines (37 loc) · 1.15 KB
/
Copy pathindex-jds.html
File metadata and controls
42 lines (37 loc) · 1.15 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Key Detection</title>
<script type="text/javascript" src="http://www.cornify.com/js/cornify.js"></script>
</head>
<body>
<h1 style="display: block; text-align: center;">enter the konami code</h1>
<script>
const keysLogged = [];
const konamiKeys = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a"];
// const codesLogged = [];
// const konamiCode = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
let flagCode = false;
document.addEventListener('keyup',(e) => {
if (!flagCode) {
console.warn('push key to array');
keysLogged.push(e.key);
// codesLogged.push(e.keyCode);
if (keysLogged.length > 10) {
console.warn('shift key from array');
keysLogged.shift();
// codesLogged.shift();
}
// if (JSON.stringify(keysLogged) === JSON.stringify(konamiKeys)) {
if (keysLogged.join('') === konamiKeys.join('')) {
flagCode = true;
console.info('START CORNIFY!!!!!');
}
} else {
console.info('KEEP CORNIFYING!!!!!');
}
});
</script>
</body>
</html>