Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.