konami-emoji-blast
konami-emoji-blast
is a package that combines two others:
konami-code-js
: detects when the user has entered the Konami Code…emoji-blast
: …to startemojiBlast()
s until the code is entered again.
If a user presses up up down down left right left right b a on their keyboard or taps it on their mobile phone, emoji blasts will start firing on the page. Triggering the code again stops the blasts.
Getting Started
Section titled “Getting Started”Dedicated integrations exist for adding konami-emoji-blast
with common frameworks:
Otherwise, this page will get you started as quickly as possible.
Quick Bundler Start
Section titled “Quick Bundler Start”If you’re writing JavaScript or TypeScript with a bundler, first install the konami-emoji-blast
package as a dependency:
npm i konami-emoji-blast
You can then import it in your code to access its initializeKonamiEmojiBlast
function:
import { initializeKonamiEmojiBlast } from "konami-emoji-blast";
initializeKonamiEmojiBlast();
Quick HTML Start
Section titled “Quick HTML Start”If you’re directly writing an .html
document, plop this 👇 at the end of your <body>
:
<script async src="https://unpkg.com/konami-emoji-blast/dist/now.js"></script>
That 👆 loads konami-emoji-blast
soon after your page loads to set up the Konami Code with no configuration.
👌.
You might want a little more fine-grained control over when the connection is created.
Use this 👇 alternate script to create a global initializeKonamiEmojiBlast
function:
<script src="https://unpkg.com/konami-emoji-blast/dist/global.js"></script><script> initializeKonamiEmojiBlast();</script>
konami-emoji-blast
export a single function:
initializeKonamiEmojiBlast
: Initializes the Konami Code listener on the page.
initializeKonamiEmojiBlast
Section titled “initializeKonamiEmojiBlast”import { initializeKonamiEmojiBlast } from "konami-emoji-blast";
initializeKonamiEmojiBlast();
This will create a new konami-code-js
KonamiCode
instance to listen for user input.
It will call emojiBlasts
whenever the code is detected.
initializeKonamiEmojiBlast()
returns a cancellation function that cancels any pending work.
// Commence code listening!...const cancel = emojiBlasts();
// ...but not after ten seconds.setTimeout(stop, 10000);
initializeKonamiEmojiBlast
Options
Section titled “initializeKonamiEmojiBlast Options”initializeKonamiEmojiBlast
may take a single optional parameter, onActivate
.
onActivate
Section titled “onActivate”A function to run whenever the user inputs the Konami Code.
import { initializeKonamiEmojiBlast } from "konami-emoji-blast";
initializeKonamiEmojiBlast(() => { console.log("Commence blasting! 🎆");});