Skip to content

Instantly share code, notes, and snippets.

@hugeuser
Created April 8, 2014 19:59
Show Gist options
  • Save hugeuser/10181755 to your computer and use it in GitHub Desktop.
Save hugeuser/10181755 to your computer and use it in GitHub Desktop.
Easter Eggs
(function ( $ ) {
var i, j = 0;
var matching = false;
var secret = [
{
cheat: 'monochrome',
code: [77, 79, 78, 79, 67, 72, 82, 79, 77, 69]
},
{
cheat: 'sepia',
code: [83, 69, 80, 73, 65]
},
{
cheat: 'acid',
code: [65, 67, 73, 68]
}
// etc.
];
var len = secret.length;
$(document).keydown(function easter(e) {
for (i = len; i--;) {
if(e.keyCode === secret[i].code[j]) {
j++;
if(j === secret[i].code.length) {
$(document).unbind('keydown', easter);
activate(secret[i].cheat);
}
matching = true;
break; // we have (beginnings of) a match…
}
}
if (!matching) {
j = 0; // otherwise, reset
}
matching = false;
});
function activate(code){
$.getScript('/path/to/cheat.js', function(){ HUGE.cheat.init(code);
});
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment