Last active
December 13, 2015 21:18
-
-
Save khepin/4975753 to your computer and use it in GitHub Desktop.
EasterEgg.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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