Konami code using jQuery

3 comments

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!");
    });
});

Add a comment

3 comments