One of the famous easter eggs. http://en.wikipedia.org/wiki/Konami_code
-
-
Save tsaniel/1188477 to your computer and use it in GitHub Desktop.
Konami Code easter egg
This file contains hidden or 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
function( | |
a, // callback function | |
b // placeholder for key stack | |
){ | |
document.onkeyup = function(e){ | |
/113302022928$/.test( // check if the latest pressed codes are Konami Code | |
b += [((e||self.event).keyCode-37)]) // push the code it into the stack | |
) && a() // callback if pressed Konami Code | |
} | |
} |
This file contains hidden or 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
function(f,a){document.onkeyup=function(e){/113302022928$/.test(a+=[((e||self.event).keyCode-37)])&&f()}} |
This file contains hidden or 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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains hidden or 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
{ | |
"name": "KonamiCodeEasterEgg", | |
"description": "The famous Konami Code easter egg.", | |
"keywords": [ | |
"Konami Code", | |
"easter egg", | |
"fun" | |
] | |
} |
This file contains hidden or 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
<!DOCTYPE html> | |
<title>Konami Code easter egg</title> | |
<div>Expected value: <b>Try to press (↑ ↑ ↓ ↓ ← → ← → B A)</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
// write a small example that shows off the API for your example | |
// and tests it in one fell swoop. | |
var myFunction = function(f,a){document.onkeyup=function(e){/113302022928$/.test(a+=[((e||self.event).keyCode-37)])&&f()}}; | |
myFunction(function(){alert('onKonamiCode triggered!')}) | |
</script> |
Correct.
http://jsbin.com/ofitoj/edit#preview works fine in IE8, Chrome Canary, Opera 12 and Firefox Aurora. I think it's safe to get rid of the self.
The magic limit is 4294967296, so we'll need to fit the 10 keycodes 38, 38, 40, 40, 37, 37, 39, 39, 65, 66 inside it.
Thanks to the string coercion with array literal trick, we save another byte.
Just 78 bytes:
function(f,a){onkeyup=function(e){/113302022928$/.test(a+=[e.which-37])&&f()}}
If you set a as 0, you can get away with
function(f,a){document.onkeyup=function(e){(a+=[(e||self.event).keyCode-37])%1e12==113302022928&&f()}}
// as in
(function(f,a){document.onkeyup=function(e){(a+=[(e||self.event).keyCode-37])%1e12==113302022928&&f()}})(callback, 0)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I take it the correct values for 0x12345678 and 1337 are yet to be determined?