Skip to content

Instantly share code, notes, and snippets.

@iamandrewluca
Created May 15, 2019 07:14
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 iamandrewluca/f2840d19fa9ba60a95818ab795dd8e14 to your computer and use it in GitHub Desktop.
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
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