I Konamified this site, want to konamify yours?

So, I had a spare moment the other day and after seeing Konami Code Sites I decided to see about adding the Konami code to this site – just to see how one might work such a thing. I dusted off my javascript skillz and wrote a weak ass script that seems to do the trick cross browser – the payload (playing a little mp3) may require a plugin on IE, but I think most of the newer IE’s won’t have a problem, as the actual detection of a successful code entry seems to work. Give it a shot!

If you’re interested in the code it’s super easy – hopefully, I don’t commit any js faux pas, I’ve copied the code in at the bottom. Really straight forward, just comparing arrays, basically. There’s probably a smarter way to do it, but I just wanted to do something quick and this is the first way that occurred to me. I wanted something that only worked once, so subsequent code entries weren’t even looked at.

The hard part is figuring out what you want to do when you hit the code – that all happens in the doit function so that’s where you can customize your very own fancy function. To actually put it in action, you just take the script, put it in a .js file and add it to your html – then you can be a good javascript citizen and unobtrusively script it after your page load, but I wanted this to start listening immediately, so I actually hardcoded it into the html in the body onkeydown attribute. That’s just how I roll.

At any rate, give it a shot and let me know if it doesn’t work here. Also, if you want to grab it and use it yourself, feel free – let me know where it ends up because I’d love to see it!

(sorry, wordpress insists on doing some htmlifying – so you see some extra crazy tagging going on in this code. Here’s a link straight to the konami.js file.)

hadouken = {<br /> done: 0,<br /> theseq: [],<br /> thecorrectseq: [38, 38, 40, 40, 37, 39, 37, 39, 66, 65 ],<br /> 'check': function (e) {<br /> if( this.done ) { return; }</p> <p> e = e || window.event;</p> <p> var elt = e.target ? e.target : e.srcElement;<br /> if( elt.tagName == 'INPUT' || elt.tagName == 'TEXTAREA' ) { return; }</p> <p> var key = window.event ? e.keyCode : e.which;</p> <p> if( this.thecorrectseq[this.theseq.length] == key ) {<br /> this.theseq.push(key);<br /> if( this.thecorrectseq.length == this.theseq.length ) {<br /> this.doit();<br /> this.done = 1;<br /> }<br /> }<br /> else {<br /> this.theseq = [];<br /> }<br /> },<br /> doit: function() {<br /> var konamispan = document.createElement('span');<br /> konamispan.innerHTML =<br /> '<span><object width="1" height="1"><param name="src" value="/wp-content/themes/akon-082/media/konami.mp3"><embed src="/wp-content/themes/akon-082/media/konami.mp3" autostart="true" hidden="true" loop="false"></object></span>';<br /> document.body.appendChild(konamispan);<br /> }<br /> };

blog comments powered by Disqus

Not Found

Sorry, but what you are looking for isn't here...