0.1.1 • Published 2 years ago
cheatz v0.1.1
cheatz
a small and dependecy free js library to hide easter eggs on your website. You can use it to hide secret cheatcodes and it also includes a small utility to echo keys.
How to
npm install cheatzthen either use the dist/ files as cjs or the src files in type="module" like so:
<script type="module">
import Cheatz from './Cheatz.js';
import Keyecho from './Keyecho.js';
let keyEcho = null;
addEventListener("DOMContentLoaded", () => {
keyEcho = new Keyecho("body");
new Cheatz("body", "i d d q d", function () {alternatively you can use the statically hosted lib on surge including it like so:
<script src="https://cheatz.surge.sh/cheatz.js"></script>
<script src="https://cheatz.surge.sh/keyecho.js"></script>Then you can set the Cheat Codes like so: Cheatz
addEventListener("DOMContentLoaded", () => {
// Konami code
new Cheatz("body", "UP UP DOWN DOWN LEFT RIGHT LEFT RIGHT A B", function () { /* DO SOMETHING */});
});You can customise also other key codes passing it as 4th parameter of new Cheatz().
constructor(mountPoint, sequence, callback, additionalMap = {})the default ones are those, I am using the event.key value, defined in here.
const keyMaps = {
"UP": "ArrowUp",
"DOWN": "ArrowDown",
"LEFT": "ArrowLeft",
"RIGHT": "ArrowRight",
"ENTER": "Enter",
"TAB": "Tab",
"CTRL": "Control",
"ALT": "Alt",
"SUPER": "Meta"
};Keyecho
let keyEcho = null;
addEventListener("DOMContentLoaded", () => {
keyEcho = new Keyecho("body");
});This will listen to every key press and echo them at the bottom right of the page.