Skip to content

Instantly share code, notes, and snippets.

@midu
Last active November 1, 2019 11:29
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save midu/11226724 to your computer and use it in GitHub Desktop.
Save midu/11226724 to your computer and use it in GitHub Desktop.
Watch for the konami code on your page
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