Created
May 15, 2019 07:14
-
-
Save iamandrewluca/f2840d19fa9ba60a95818ab795dd8e14 to your computer and use it in GitHub Desktop.
This script will spy the page for what you type and when will match what you find will inform
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
function spy(regexp, callback) { | |
let state = ""; | |
document.addEventListener("keydown", function(e) { | |
state += e.key; | |
console.log(e.key); | |
const match = state.match(regexp); | |
if (match) { | |
callback(match[0]); | |
state = ""; | |
} | |
}); | |
} | |
spy(/typing this should catch$/, function(code) { | |
console.log(code); | |
alert(code); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment