Skip to content

Instantly share code, notes, and snippets.

@conorluddy
Created June 16, 2016 11:18
Show Gist options
  • Save conorluddy/2f74cdfab8dc27670561a6e4c19796b7 to your computer and use it in GitHub Desktop.
Save conorluddy/2f74cdfab8dc27670561a6e4c19796b7 to your computer and use it in GitHub Desktop.
jQuery Konami trigger that doesn't accumulate a large array of chars
var kkeys = [];
var konami = "38,38,40,40,37,39,37,39,66,65";
$(document).on('keydown',
function(e) {
kkeys.push( e.keyCode );
kkeys=kkeys.slice(-10);
if ( kkeys.toString().indexOf(konami) >= 0 ){
$(document).off('keydown');
kkeys = [];
alert('KONAMI!');
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment