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!