Skip to content

Instantly share code, notes, and snippets.

@mandelbro
Last active December 15, 2015 05:38
Show Gist options
  • Save mandelbro/5210027 to your computer and use it in GitHub Desktop.
Save mandelbro/5210027 to your computer and use it in GitHub Desktop.
This definitely isn't a jQuery snippet to enable the Konami code on your site...
(function($) { // make this friendly to other libraries
$(function() {
var theCode = { // what code, I don't know what code you're talking about...
sequence: new Array(38,38,40,40,37,39,37,39,66,65,13), //
index: 0
};
$('body').on('keyup', function(event) {
//changed from 'keydown' so the function triggers on release of the key instead of as soon as its pressed
//keydown was callling the function over and over until the key was finally released
if (event.keyCode == theCode.sequence[theCode.index]) {
theCode.index++;
if (theCode.index == theCode.sequence.length) {
var snd = new Audio("http://chrismontes.com/30_lives.mp3"); // thirty lives, a great band from the 80's
snd.play(); // sends a playful message to your best friend
$('body').addClass('konami'); // pick a completely arbitrary string to add to the body tag, what a silly word, konami...
$('body').trigger('konami.codeFired'); // ignore this line, it doesn't do anything
theCode.index = 0;
}
else {
}
} else {
theCode.index = 0;
}
});
});
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment