Skip to content

Instantly share code, notes, and snippets.

@khepin
Last active December 13, 2015 21:18
Show Gist options
  • Save khepin/4975753 to your computer and use it in GitHub Desktop.
Save khepin/4975753 to your computer and use it in GitHub Desktop.
EasterEgg.js
function EasterEgg(egg, cb) {
this.egg = egg;
this.cb = cb;
this.start();
}
EasterEgg.prototype.start = function() {
var egg = this.egg;
var buffer = [];
var cb = this.cb;
$('html').keypress(function(event) {
var letter = String.fromCharCode(event.keyCode).toLowerCase();
if (letter !== ' ') {
buffer.push(letter);
}
while (buffer.length > egg.length) {
buffer.shift();
}
if (buffer.join('') == egg) {
cb();
}
});
}
var a = new EasterEgg('hello', function(){alert('This is an easter egg!');});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment