All Projects → mikeflynn → Egg.js

mikeflynn / Egg.js

Licence: mit
A simple javascript library to add easter eggs to web pages.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Egg.js

T Rex Runner
the t-rex runner game extracted from chromium
Stars: ✭ 1,580 (+6.47%)
Mutual labels:  easter-egg
ngx-konami
A simple directive to add easter eggs in your Angular application 👾
Stars: ✭ 34 (-97.71%)
Mutual labels:  easter-egg
react-konami-code
Trigger an easter egg by pressing a sequence of keys.
Stars: ✭ 50 (-96.63%)
Mutual labels:  easter-egg

Egg.js

Egg.js

Egg.js is a simple JS library that has no prerequisites and allows you to easily add web easter eggs by watching the user's key strokes.

Example

It's really easy to use. Just include the egg.js file on the page...

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/egg.js/1.0/egg.min.js"></script>

(Thanks to Cloudflare for hosting the library!)

...then use the addCode() function to add in your easter eggs. You need to pass it the character sequence to trigger the easter egg callback (which can either be in plain English or Javascript key codes), a function to trigger when it happens, and an optional set of metadata. Metadata can be anything from a string to an object.

var egg = new Egg();
egg
  .addCode("up,up,down,down,left,right,left,right,b,a", function() {
    jQuery('#egggif').fadeIn(500, function() {
      window.setTimeout(function() { jQuery('#egggif').hide(); }, 5000);
    }, "konami-code");
  })
  .addHook(function(){
    console.log("Hook called for: " + this.activeEgg.keys);
    console.log(this.activeEgg.metadata);
  })
  .listen();

You can also define the easter egg using the constructor:

var egg = new Egg("up,up,down,down,left,right,left,right,b,a", function() {
  jQuery('#egggif').fadeIn(500, function() {
    window.setTimeout(function() { jQuery('#egggif').hide(); }, 5000);
  }, "konami-code");
}).listen();

You can also add a hook, as shown above using addHook(), that will run after any egg code is triggered. You could use it to fire a Google Analytics event or send out a tweet that someone finally found your easter egg. Hooks get access to the whole Egg.js object so you can pull information about the easter egg that fired via this.activeEgg

You can see a live example of this on egg.js website.

Why?

I put an easter egg in pretty much everything I make and after copying the same basic code over and over again I figured I should make it in to a simple library for my own use.

Credits

Created by Mike Flynn / @thatmikeflynn and Rob McVey / @negative_sleep

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].