diff options
| author | Fuwn <[email protected]> | 2020-11-08 21:01:55 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2020-11-08 21:01:55 -0800 |
| commit | 6f4d4f283affaf50b4c242b1ff0a275c22af81e6 (patch) | |
| tree | d8e3fed1b3e2dc8ab9db4a5229f8bcba28548599 /public/js | |
| parent | fix: make tweet this https (diff) | |
| download | blog-6f4d4f283affaf50b4c242b1ff0a275c22af81e6.tar.xz blog-6f4d4f283affaf50b4c242b1ff0a275c22af81e6.zip | |
feat: (desc)
feat:
- 404 redirect
- darkmode boilerplate
- konami ee
- "back to home" to "back home"
- "read on" to "read more"
- id main stylesheets for later darkmode
- console log ee and darmode extension
Diffstat (limited to 'public/js')
| -rw-r--r-- | public/js/konami.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/public/js/konami.js b/public/js/konami.js new file mode 100644 index 0000000..5f09304 --- /dev/null +++ b/public/js/konami.js @@ -0,0 +1,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; + } +}; |