Last active
November 1, 2019 11:29
-
-
Save midu/11226724 to your computer and use it in GitHub Desktop.
Watch for the konami code on your page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
userInputs = [] | |
konami = [ | |
38, 38, # ↑ ↑ | |
40, 40, # ↓ ↓ | |
37, 39, # ← → | |
37, 39, # ← → | |
66, 65 # B A | |
16, 13 # ⇧ ↩ (shift, enter) | |
] | |
sameArrays = (a, b) -> | |
return false if a.length != b.length | |
for value, index in a | |
return false if value != b[index] | |
true | |
$(document).on 'keyup', (e) -> | |
key = e.which | |
if key == konami[userInputs.length] | |
userInputs.push key | |
else | |
userInputs = [] | |
if sameArrays(userInputs, konami) | |
alert('konami') # do something cooler than that | |
array = [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment