Created
October 5, 2016 16:23
-
-
Save yi-jiayu/3240fe01e440e81d6df6a592827b4211 to your computer and use it in GitHub Desktop.
Automated script to play the Telegram Gaming Platform demo game Math Battle when played in a browser using devtools. May cause highscore ban.
This file contains hidden or 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 target = document.getElementById('task'); | |
var observer = new MutationObserver(function(mutations) { | |
var x = parseInt(document.querySelector('#task_x').textContent, 10); | |
var y = parseInt(document.querySelector('#task_y').textContent, 10); | |
var op = document.querySelector('#task_op').textContent; | |
var eq = parseInt(document.querySelector('#task_res').textContent, 10); | |
console.log(x, y, op, eq); | |
var correct = false; | |
switch (op) { | |
case '+': | |
console.log(`${x} + ${y} = ${x+y}`); | |
correct = x + y == eq; | |
break; | |
case '–': | |
console.log(`${x} - ${y} = ${x-y}`); | |
correct = x - y == eq; | |
break; | |
case '×': | |
console.log(`${x} x ${y} = ${x*y}`); | |
correct = x * y == eq; | |
break; | |
case '/': | |
console.log(`${x} / ${y} = ${x/y}`); | |
correct = x / y == eq; | |
break; | |
} | |
console.log(correct); | |
// press the correct button | |
// timeout added cos otherwise your score easily reaches 20k | |
if (correct) { | |
var correctButton = document.getElementById('button_correct'); | |
window.setTimeout(function () {correctButton.click.apply(correctButton)}, 100); | |
} else { | |
var wrongButton = document.getElementById('button_wrong'); | |
window.setTimeout(function() {wrongButton.click.apply(wrongButton)}, 100); | |
} | |
}); | |
var config = {subtree: true, characterData: true}; | |
observer.observe(target, config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment