Skip to content

Instantly share code, notes, and snippets.

@A35G
Created January 21, 2016 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A35G/3dcb000bacd7804b243d to your computer and use it in GitHub Desktop.
Save A35G/3dcb000bacd7804b243d to your computer and use it in GitHub Desktop.
Pieces of code useful for sketching an easter egg in a website or a web app. By entering a word or a sequence of characters / symbols / or other, it is possible to perform a function if the condition is true; In case of 5 second pause between typing and the other, the sequence is emptied.
var sequence = '';
var timeout;
var reset_s = function() {
sequence = '';
}
$(document).on("keypress", function(event) {
if(timeout)
clearTimeout(timeout);
var key = event.which || event.keyCode || 0;
var tag = event.target.tagName.toLowerCase();
if (tag != 'input' && tag != 'textarea') {
//console.log(String.fromCharCode(key));
sequence = sequence + String.fromCharCode(key);
console.log(sequence);
if (sequence == "test") {
alert("complete");
reset_s();
}
} else {
reset_s();
}
timeout = setTimeout(reset_s, 5000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment