From d8b68deaec1a913cc6659083ac700a3979e9669f Mon Sep 17 00:00:00 2001 From: s1n Date: Mon, 28 Oct 2019 17:12:18 -0700 Subject: change konami to single page :))) --- js/app.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/app.js b/js/app.js index eccb561..5810d16 100644 --- a/js/app.js +++ b/js/app.js @@ -30,9 +30,21 @@ var allowedKeys = { 39: 'right', 40: 'down', 65: 'a', - 66: 'b' + 66: 'b', + 8: 'backspace' }; +// To somewhat stop backspace/ refresh spamming +window.addEventListener('keydown', function (event) { + + if (event.keyCode === 8) { + + event.preventDefault(); + + return false; + } +}); + // The 'official' Konami Code sequence var konamiCode = ['up', 'up', 'down', 'down', 'left', 'right', 'left', 'right', 'b', 'a']; @@ -62,9 +74,72 @@ document.addEventListener('keydown', function (e) { } }); +// Back to normal sequence +var backCode = ['backspace']; + +var backCodePosition = 0; + +document.addEventListener('keydown', function (e) { + var key = allowedKeys[e.keyCode]; + var requiredKey = backCode[backCodePosition]; + + if (key == requiredKey) { + + backCodePosition++; + + if (backCodePosition == backCode.length) { + deactivateCheats(); + backCodePosition = 0; + } + } else { + backCodePosition = 0; + } +}); + +function swapStyleSheet(sheet) { + document.getElementById('pagestyle').setAttribute('href', sheet); +} + +// Change favicon +document.head = document.head || document.getElementsByTagName('head')[0]; + +function changeFavicon(src) { + var link = document.createElement('link'), + oldLink = document.getElementById('dynamic-favicon'); + link.id = 'dynamic-favicon'; + link.rel = 'shortcut icon'; + link.href = src; + if (oldLink) { + document.head.removeChild(oldLink); + } + document.head.appendChild(link); +} + function activateCheats() { + + swapStyleSheet('/konami/css/main.css'); + // I overworked for this smh... + + changeFavicon('/konami/assets/images/small-spinning-globe3.gif'); + + var x = document.getElementById("music"); + function playAudio() { + x.play(); + } + playAudio() +} + +function deactivateCheats() { - window.location.href = "/konami"; + swapStyleSheet('/css/main.css'); + + changeFavicon('favicon.ico'); + + var x = document.getElementById("music"); + function pauseAudio() { + x.pause(); + } + pauseAudio() } var TxtRotate = function (el, toRotate, period) { -- cgit v1.2.3