Just thought I’d chip in to the growing hype of adding some secret thing to your website accessible via the famous Konami cheat code. You can try it out right now:
On your keyboard press (in this order): Up, Up, Down, Down, Left, Right, Left, Right, B, A … then wait a sec.
To “benefit” from whatever happens you must be using a respectable browser (FF, Safari, IE7. Opera etc.) and, of course, you need to have JavaScript enabled. If it doesn’t work try clearing your cache first.
And with that I’m also releasing the “onKonamiCode” event handler:
function onKonamiCode(fn) { var codes = (function(){ var c = [38,38,40,40,37,39,37,39,66,65]; onKonamiCode.requireEnterKey && c.push(13); return c; })(), expecting = function(){ expecting.codes = expecting.codes || Array.apply({}, codes); expecting.reset = function() { expecting.codes = null; }; return expecting.codes; }, handler = function(e) { if (expecting()[0] == (e||window.event).keyCode) { expecting().shift(); if (!expecting().length) { expecting.reset(); fn(); } } else { expecting.reset(); } }; window.addEventListener ? window.addEventListener('keydown', handler, false) : document.attachEvent('onkeydown', handler); } |
Use it like this:
onKonamiCode.requireEnterKey = true; // True/false onKonamiCode(function(){ // Do something CRAZY! }); |
Have fun!
Thanks for reading! Please share your thoughts with me on Twitter. Have a great day!
Cool snippet thanks mate, James go test Konami code in jQuery home page you will see something there.
Ahah nice short & simple 🙂
Some sites use this combination as easter egg, jQuery (as said above) or Google Reader for instance !
Nice! Reminds me of the good ol’ days… 🙂
Facebook use Konami code as easter egg too.
On my website, CodeJoust Web Design I have a Konami code implementation… try it and see where it goes :D.
Great stuff, James. Last year I published a jQuery plug-in for this, but I guess my approach is a bit rusty, heh. Me likes the ‘expecting’ approach!
haha i love it 🙂 you have to use the old Sonic 1 Debug mode somewhere
UP, C, DOWN, C, LEFT, C, RIGHT, C, A, B, C START
After seeing the Konami Code Sites I thought I’d write a simple jQuery plugin to add the functionality to the site. As I was writing it your article came up! Anyway, I continued with my jQuery version, and made some options, such as the callback (for the reveal), the keycode/cheat (defaults to Konami) and option to allow multiple calls to the cheat. Anyway, have a gander at my Cheat Code jQuery plugin.
Charlieeeee!
nice set up.
i would like to add 2 notes
1. [38,38,40,40,37,39,37,39,66,65] should be [38,38,40,40,37,39,37,39,66,65,66,65] as soe games required B, A, B, A
2. personally, for OCD/ADD reasons i would remove the listener removeEventListener() after successful excecution
great work!
ha… …charlie the unicorn! FTW
Just added the Konami Code to a new website of mine which just launched this weekend;
http://www.twitpicwall.com
I used the same method as on jQuery.com but ported to Prototype 🙂
The code is very nice. But can it be used on other stuffs apart from website design?
What are the numbers for other characters? I see that 66 is b and 65 is a, but what are all the other number and letter codes?