Created
July 8, 2020 16:50
-
-
Save amitmerchant1990/05b1c20bba20711e6c9bd637c37f4585 to your computer and use it in GitHub Desktop.
Konami Code Trigger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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