@rubenarakelyan/stimulus-konami-code
v1.0.1
Published
A Stimulus controller that implements the Konami code
Downloads
11
Maintainers
Readme
@rubenarakelyan/stimulus-konami-code
@rubenarakelyan/stimulus-konami-code is a Stimulus controller to implement the Konami code on a website.
Usage
Register the controller in your application:
import { Application } from "@hotwired/stimulus"
import KonamiCode from "@rubenarakelyan/stimulus-konami-code"
const application = Application.start()
application.register("konami-code", KonamiCode)
Next, define a callback function that will be called whenever the correct keyboard sequence is entered:
function konamiCodeCallback(target) {
// `target` is the `<body>`
}
Object.assign(window, { konamiCodeCallback })
Then, add the required Stimulus data attributes to your page:
<html data-controller="konami-code" data-konami-code-callback-value="konamiCodeCallback">
...
<body data-action="keydown->konami-code#keydown">
</body>
...
</html>
Now, visit the page and enter the Konami code (↑ ↑ ↓ ↓ ← → ← → b a).
Your konamiCodeCallback
function will run.