• Stars
    star
    1,501
  • Rank 31,258 (Top 0.7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple javascript library to add easter eggs to web pages.

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

More Repositories

1

go-alexa

A collection of Amazon Echo / Alexa tools for Go development.
Go
256
star
2

gmail-clj

A Clojure library that abstracts the GMail API (not the IMAP) interface.
Clojure
33
star
3

go-dash-button

A server to handle Amazon Dash button actions; Written in golang
Go
13
star
4

quackerjack

A social post comment thread analyzer written in Golang.
Go
13
star
5

sensehat-service-ui

A minimal physical interface to turn on and off services via the Raspberry Pi Sense Hat.
Python
10
star
6

chrome-keyword-search

A Google Chrome extension for finding and highlighting given keywords on a web page.
JavaScript
4
star
7

youtube-api

A Clojure library for accessing the YouTube v3 API
Clojure
3
star
8

beats-clj

A Clojure library to interact with the Beats Music API.
Clojure
2
star
9

beats-app

A Google Chrome Packaged App for Beats Music.com
JavaScript
2
star
10

beats-sentence-to-playlist

An application that migrates Beats Music Sentences to playlists.
JavaScript
2
star
11

stltoday-paywall-buster

A user script to block the STLToday.com paywall from activating.
Swift
2
star
12

conversations-plus

Trying to make you more interesting.
JavaScript
2
star
13

echo-tunnel

A service to push Amazon Alexa commands to individual computers.
Go
1
star
14

kali-docker

A custom Kali Linux Docker build.
Dockerfile
1
star
15

Store

A localStorage javascript wrapper for caching and settings.
JavaScript
1
star
16

twitter-proxy

A simple proxy specifically to get cross domain javascript access to the Twitter v1.1 API.
JavaScript
1
star
17

fb_gameoflife

A solution (in PHP) for one of Facebook's programming challenges: Game of Life
PHP
1
star
18

chd10-roommate

Go
1
star
19

trapperkeeper

A Clojure-based image server API.
JavaScript
1
star
20

facebook_user_model

A data model for a user system written in PHP, with special attention to Facebook interaction.
PHP
1
star
21

ClojureSprites

A Clojure application to automatically create and implement a sprite from a CSS file.
Clojure
1
star