Skip to content

Instantly share code, notes, and snippets.

@amitmerchant1990
Created July 8, 2020 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitmerchant1990/05b1c20bba20711e6c9bd637c37f4585 to your computer and use it in GitHub Desktop.
Save amitmerchant1990/05b1c20bba20711e6c9bd637c37f4585 to your computer and use it in GitHub Desktop.
Konami Code Trigger
var pattern = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'];
var current = 0;
var keyHandler = function (event) {
// If the key isn't in the pattern, or isn't the current key in the pattern, reset
if (pattern.indexOf(event.key) < 0 || event.key !== pattern[current]) {
current = 0;
return;
}
// Update how much of the pattern is complete
current++;
// If complete, alert and reset
if (pattern.length === current) {
current = 0;
var confettiSettings = { target: 'confetti-holder' };
var confetti = new ConfettiGenerator(confettiSettings);
confetti.render();
}
};
// Listen for keydown events
document.addEventListener('keydown', keyHandler, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment