From 6e779c0ce8e7b467ec4cfd0aa8a24300dd9c5320 Mon Sep 17 00:00:00 2001 From: Paul Brinkmeier Date: Sun, 5 Nov 2017 02:55:36 +0100 Subject: [PATCH 1/3] Include konami code JS file --- Makefile | 1 + templates/index.theme | 1 + 2 files changed, 2 insertions(+) diff --git a/Makefile b/Makefile index bfe14e4..51250d9 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ index: pages/index.md styles/index.css mkdir -p build cp styles/index.css build/index.css + cp scripts/konami-code.js build/k.js discount-theme pages/index.md \ -o build/index.html \ -t templates/index.theme diff --git a/templates/index.theme b/templates/index.theme index 819251f..1a3a105 100644 --- a/templates/index.theme +++ b/templates/index.theme @@ -9,5 +9,6 @@
+ From 0b5a9672bcfafabf43565d70e7a272850e9daaef Mon Sep 17 00:00:00 2001 From: Paul Brinkmeier Date: Sun, 5 Nov 2017 02:55:53 +0100 Subject: [PATCH 2/3] Create secret script --- scripts/konami-code.js | 106 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 scripts/konami-code.js diff --git a/scripts/konami-code.js b/scripts/konami-code.js new file mode 100644 index 0000000..e1d1b90 --- /dev/null +++ b/scripts/konami-code.js @@ -0,0 +1,106 @@ +(function () { + /* + * A map of key codes so that you dont have to use them directly. + */ + var k = { + UP: 38, + DOWN: 40, + LEFT: 37, + RIGHT: 39, + B: 66, + A: 65 + }; + + /* + * These are the keys of the konami code (according to wikipedia). + */ + var konamiCode = [ k.UP, k.UP, k.DOWN, k.DOWN, k.LEFT, k.RIGHT, k.LEFT, k.RIGHT, k.B, k.A ]; + + /* + * In case someone enters the konami code, unleash the seven hells. + */ + onKeyStreak(konamiCode, unleashTheSevenHells); + + /* + * Keep a record of keystrokes and call a function when a certain streak is entered. + */ + function onKeyStreak (streak, callback) { + var keysPressed = []; + var eventToListenFor = 'keydown'; + + var listener = function (e) { + keysPressed.push(e.keyCode); + + console.log(keysPressed, streak); + + if (isSuffix(streak, keysPressed)) { + window.removeEventListener(eventToListenFor, listener); + callback(); + } + }; + + window.addEventListener(eventToListenFor, listener); + } + + /* + * Check whether listA is a suffix of listB. + */ + function isSuffix (listA, listB) { + if (listA.length > listB.length) { + return false; + } + + var index = 0; + + for (; index < listA.length; index++) { + if (listA[index] !== listB[listB.length - listA.length + index]) { + console.log(index); + return false; + } + } + + return true; + } + + /* + * Commit some chaos and make sure to do so at the next frame too. + */ + function unleashTheSevenHells () { + angery(); + + window.requestAnimationFrame(unleashTheSevenHells); + } + + /* + * Be an angry website. + */ + function angery () { + // This returns a list of all elements that match the CSS selector * (which are all). + var allElements = document.querySelectorAll('*'); + + // Since querySelectorAll doesn't return an array, but something zero-indexed that has a length property, we can use Array's forEach here. + // Welcome to the world of duck typing. + Array.prototype.forEach.call(allElements, makeItPretty); + } + + /* + * Makes an element pretty. + */ + function makeItPretty (element) { + element.style.color = randomColour(); + element.style.backgroundColor = randomColour(); + element.style.textAlign = randomChoice([ 'left', 'center', 'right' ]); + } + + function randomChoice (choices) { + return choices[Math.floor(Math.random() * choices.length)]; + } + + function randomColour () { + var r = Math.floor(Math.random() * 256); + var g = Math.floor(Math.random() * 256); + var b = Math.floor(Math.random() * 256); + + return 'rgb(' + r + ',' + g + ',' + b + ')'; + } +})(); From 96f1a2df5a4a1d4cf9c67f52e31080f67bf6bf76 Mon Sep 17 00:00:00 2001 From: Paul Brinkmeier Date: Sun, 5 Nov 2017 02:56:50 +0100 Subject: [PATCH 3/3] Refrain from littering the browser console --- scripts/konami-code.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/konami-code.js b/scripts/konami-code.js index e1d1b90..068460e 100644 --- a/scripts/konami-code.js +++ b/scripts/konami-code.js @@ -31,8 +31,6 @@ var listener = function (e) { keysPressed.push(e.keyCode); - console.log(keysPressed, streak); - if (isSuffix(streak, keysPressed)) { window.removeEventListener(eventToListenFor, listener); callback();