Skip to content

Instantly share code, notes, and snippets.

@daybarr
Created February 25, 2023 22:31
Show Gist options
  • Save daybarr/88ca41425bdca0ac7d1db46d5c3133c6 to your computer and use it in GitHub Desktop.
Save daybarr/88ca41425bdca0ac7d1db46d5c3133c6 to your computer and use it in GitHub Desktop.
(function loop() {
var delay = 500 + Math.floor(Math.random() * 500);
setTimeout(() => {
var el;
if (el = document.querySelector('ttr-game-question.current-game-question')) {
var sum = el.innerText;
var [x,op,y] = sum.split(' ');
var answer = (op=='×') ? (x*y) : (x/y);
answer.toString().split('').forEach(x =>
dispatchEvent(new KeyboardEvent("keydown", {
"key": x,
"keyCode": 48+parseInt(x,10),
"which": 48+parseInt(x,10),
"code": "Digit"+x,
}))
);
dispatchEvent(new KeyboardEvent("keydown", {
"key": "Enter",
"keyCode": 13,
"which": 13,
"code": "Enter",
}));
} else if (el = document.evaluate("//button[contains(., 'Play again')]", document, null, XPathResult.ANY_TYPE, null ).iterateNext()) {
el.click();
}
loop();
}, delay);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment