Konami code using jQuery

The Konami code is a pretty cool way to hide easter eggs on your website. If you want to include the code on your site but something like Konami-JS is a little too heavy you could try this small jQuery snippet.

function konami(fn) {
    var input = "";
    var pattern = "3838404037393739666513";
    $(document).keydown(function(e) {
        input += e.keyCode;
        if (input.indexOf(pattern) !== -1) {
            fn();
            input = "";
        }
    });
}

The function gets one argument: a function that is executed when the code is passed correctly. Use it like this:

$(document).ready(function() {
    konami(function() {
        alert("You did the Konami! W00t!");
    });
});

3 comments on “Konami code using jQuery”

Add your comments »

  1. Tweets die vermelden Always fun: include the Konami code in your website using this small jQuery snippet: -- Topsy.com wrote:

    [...] Dit blogartikel was vermeld op Twitter door OOBE, Hay Kranen. Hay Kranen heeft gezegd: Always fun: include the Konami code in your website using this small jQuery snippet: http://bit.ly/catcXG [...]

    Geplaatst op Friday 07-05-2010
  2. frenkie wrote:

    Yep, great code! Every day is Easter ;) Only wish somebody would invent a way for the iPhone to input it.

    Geplaatst op Friday 07-05-2010
  3. Hay wrote:

    Well, you can use KonamiJS (link in the post) for that, it has a iPhone input option.

    Geplaatst op Saturday 08-05-2010

Leave your comments here

» An overview of all articles can be found in the archive.

Hi! I'm Hay. I make art, do projects and blog here. Read more »

Projects

More Hay at...

Archives by month