diff options
| author | s1nical <[email protected]> | 2019-08-09 15:34:28 -0700 |
|---|---|---|
| committer | s1nical <[email protected]> | 2019-08-09 15:34:28 -0700 |
| commit | 52f74fa6435494b583dc17c0710cc6059fc8aff7 (patch) | |
| tree | 93e696c2c2a5820fa5034a756b075f0da7d5dc93 /konami/js | |
| parent | take out unused loader dupes (diff) | |
| download | s1n.pw-admin-52f74fa6435494b583dc17c0710cc6059fc8aff7.tar.xz s1n.pw-admin-52f74fa6435494b583dc17c0710cc6059fc8aff7.zip | |
Konami Code ;)
Diffstat (limited to 'konami/js')
| -rw-r--r-- | konami/js/main.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/konami/js/main.js b/konami/js/main.js new file mode 100644 index 0000000..455cd00 --- /dev/null +++ b/konami/js/main.js @@ -0,0 +1,102 @@ +// SCROLLING TITLE +var space = " "; +var speed = "60"; +var pos = 0; +var msg = "// s1n.ical // Landing Page "; + +function Scroll() { + document.title = msg.substring(pos, msg.length) + space + msg.substring(0, pos); + pos++; + if (pos > msg.length) pos = 0; + window.setTimeout("Scroll()", speed); +} +Scroll(); + +// KONAMI CODE FOR TOASTY + +// a key map of allowed keys +var allowedKeys = { + 37: 'left', + 38: 'up', + 39: 'right', + 40: 'down', + 65: 'a', + 66: 'b' +}; + +// the 'official' Konami Code sequence +var konamiCode = ['up', 'up', 'down', 'down', 'left', 'right', 'left', 'right', 'b', 'a']; + +// a variable to remember the 'position' the user has reached so far. +var konamiCodePosition = 0; + +// add keydown event listener +document.addEventListener('keydown', function (e) { + // get the value of the key code from the key map + var key = allowedKeys[e.keyCode]; + // get the value of the required key from the konami code + var requiredKey = konamiCode[konamiCodePosition]; + + // compare the key with the required key + if (key == requiredKey) { + + // move to the next key in the konami code sequence + konamiCodePosition++; + + // if the last key is reached, activate cheats + if (konamiCodePosition == konamiCode.length) { + activateCheats(); + konamiCodePosition = 0; + } + } else { + konamiCodePosition = 0; + } +}); + +function activateCheats() { + + var audio = new Audio('https://s3-eu-west-1.amazonaws.com/wdildnproject2/toasty.mp3'); + audio.play(); +} + +var TxtRotate = function (el, toRotate, period) { + this.toRotate = toRotate; + this.el = el; + this.loopNum = 0; + this.period = parseInt(period, 10) || 2000; + this.txt = ''; + this.tick(); + this.isDeleting = false; +}; + +TxtRotate.prototype.tick = function () { + var i = this.loopNum % this.toRotate.length; + var fullTxt = this.toRotate[i]; + + if (this.isDeleting) { + this.txt = fullTxt.substring(0, this.txt.length - 1); + } else { + this.txt = fullTxt.substring(0, this.txt.length + 1); + } + + this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>'; + + var that = this; + var delta = 300 - Math.random() * 100; + + + setTimeout(function () { + that.tick(); + }, delta); +}; + +window.onload = function () { + var elements = document.getElementsByClassName('txt-rotate'); + for (var i = 0; i < elements.length; i++) { + var toRotate = elements[i].getAttribute('data-rotate'); + var period = elements[i].getAttribute('data-period'); + if (toRotate) { + new TxtRotate(elements[i], JSON.parse(toRotate), period); + } + } +};
\ No newline at end of file |