Skip to content

Instantly share code, notes, and snippets.

@aarongustafson
Last active December 27, 2015 02:19
Show Gist options
  • Save aarongustafson/7251714 to your computer and use it in GitHub Desktop.
Save aarongustafson/7251714 to your computer and use it in GitHub Desktop.
The classic Contra cheat code in jQuery
(function($){
$.fn.konamiCode = function( callback ){
var current_keys = [],
current_keys_str = '',
unlock_code = '38 38 40 40 37 39 37 39 66 65';
$('body').on('keydown',function(e){
current_keys.push( e.keyCode );
current_keys_str = current_keys.join(' ');
if ( unlock_code.indexOf( current_keys_str ) !== 0 )
{
current_keys = [];
}
if ( current_keys_str === unlock_code )
{
callback();
}
});
// maintain the chain
return this;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment