Add Keyboard-triggered Easter Eggs To Webpage – egg.js

Category: Javascript , Recommended | May 16, 2019
Author: mikeflynn
Views Total: 156
Official Page: Go to website
Last Update: May 16, 2019
License: MIT

Preview:

Add Keyboard-triggered Easter Eggs To Webpage – egg.js

Description:

egg.js is a small (1.5kb) vanilla JavaScript library that adds easter eggs triggered by keyboard sequences to your webpage.

For example, you can trigger a custom function when the users type the famous Konami Code (up, up, down, down, left, right, left, right, B, A) on the webpage.

How to use it:

Download and put the egg.js library right before the closing body tag.

<script src="egg.min.js"></script>

Initialize the egg.js library.

var egg = new Egg();

Define a sequence of keyboard keys and specify a function to trigger as follows:

egg.addCode("up,up,down,down", function() {
  alert('done')
}).listen();

Trigger a function after any egg code is triggered.

egg.addCode("up,up,down,down", function() {
  alert('done')
}).addHook(function(){
  console.log("Hook called for: " + this.activeEgg.keys);
  console.log(this.activeEgg.metadata);
}).listen();

You Might Be Interested In:


Leave a Reply