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
44
45
46
47
48
|
const allowedKeys = {
37: "left",
38: "up",
39: "right",
40: "down",
65: 'a',
66: 'b'
};
const konamiCode = ["up", "up", "down", "down", "left", "right", "left", "right", 'b', 'a'];
let konamiCodePosition = 0;
let cheatState = false;
document.addEventListener("keydown", (event) => {
if (event.keyCode === 8) {
event.preventDefault();
return false;
}
});
document.addEventListener("keydown", (e) => {
let key = allowedKeys[e.keyCode];
let requiredKey = konamiCode[konamiCodePosition];
if (key == requiredKey) {
konamiCodePosition++;
if (konamiCodePosition == konamiCode.length) {
Cheats();
konamiCodePosition = 0;
}
} else { konamiCodePosition = 0; }
});
const swapStyleSheet = (id, sheet) => {
document.getElementById(id).setAttribute("href", sheet);
};
const Cheats = () => {
if (!cheatState) {
swapStyleSheet("main-style", "");
swapStyleSheet("hl-style", "");
cheatState = !cheatState;
} else if (cheatState) {
swapStyleSheet("main-style", "/css/style.css");
swapStyleSheet("hl-style", "/css/tomorrow.min.css");
cheatState = !cheatState;
}
};
|