Created
January 21, 2016 23:51
-
-
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.
This file contains 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
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