Skip to content

Instantly share code, notes, and snippets.

@padawin
Forked from 140bytes/LICENSE.txt
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save padawin/10396730 to your computer and use it in GitHub Desktop.
Save padawin/10396730 to your computer and use it in GitHub Desktop.

Konami Code

< 140 bytes Konami Code

function(a,c){ // a == the secret action to execute
// c = a placeholder to log the index of
// the next key which is expected
// in the code
document.onkeyup=function(e){ //
c=( // Update the value of c depending on the
// typed key
(
e||self.event // Browser compat
).keyCode-37 // Substraction to have as many
// lower-than-ten keys as possible
)==[1,1,3,3,0,2,0,2,29,28][c] // If the typed key is the current key
// in the code
&&
( // c will be incremented, but
c==9 // if, when incremented, c == 9, the
// code is complete, so
&&a() // execute the action
||c+1 // overwise, increment c
)
||
0; // else, if the key is not the next in
// the code, reset the cursor
}
}
function(a,c){document.onkeyup=function(e){c=((e||self.event).keyCode-37)==[1,1,3,3,0,2,0,2,29,28][c]&&(c==9&&a()||c+1)||0;}}
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.
{
"name": "KonamiCode",
"description": "140bytes implementation of the Konami Code",
"keywords": [
"Konami",
"Code",
"Konami Code",
"Easter",
"Egg",
"Easter egg"
]
}
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var action=function(){
console.log("konami");
};
(function(a,c){document.onkeyup=function(e){c=((e||self.event).keyCode-37)==[1,1,3,3,0,2,0,2,29,28][c]&&(c==9&&a()||c+1)||0;}})(action);
</script>
</head>
<body></body>
</html>
@atk
Copy link

atk commented Apr 11, 2014

That's been done before, and even smaller: https://gist.github.com/tsaniel/1188477

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment