Monday, August 17, 2009

Konami Code as DOM Event

If You do not know what is the Konami Code you are too young, or not geek at all.
In both cases, it does not matter, nobody is perfect, but what we should know is that some truly affectionate developer though to put this code to enable secret user powers, even if the the software is, as example, extremely recent.

So why not? Why can't we all have our secret mode in the most popular platform as the World Wide Web is?

Konami Code Event



var onkonamicode = function(el, fn){
// The Super Code Event by WebReflection - Mit Style
function onkonamicode(e){
konamicode.push((e || event).keyCode || e.charCode);
if(
konamicode.length === 10 &&
konamicode.join(".") === "38.38.40.40.37.39.37.39.66.65"
){
if(el.removeEventListener)
el.removeEventListener("keydown", onkonamicode, false);
else
el.detachEvent("onkeydown", onkonamicode);
fn(e);
};
clearTimeout(i);
i = setTimeout(clear, 1000);
};
function clear(){
konamicode = [];
};
var konamicode = [], i = 0;
if(el.addEventListener)
el.addEventListener("keydown", onkonamicode, false);
else
el.attachEvent("onkeydown", onkonamicode);
};


How To Activate Konami Code


It is that simple:

onkonamicode(document, function(e){
alert("access guaranteed");
});

Now try to perform the magic sequence and that's it, you have extra power!

No comments:

Post a Comment