omidsani / AI for Telegram Game Bot Math Battle

// ==UserScript==
// @name         AI for Telegram Game Bot Math Battle
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  AI for Telegram Game Bot Math Battle. Get smart and fast!
// @author       You
// @match        https://tbot.xyz/math/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    alert('AI enabled! Press (or hooold) "a" to auto answer! :)\nNow you can be super smart! :D');
    document.body.addEventListener('keydown',function(e) {
        switch(e.keyCode) {
            case 65:	// 'a'
                var correct = checkStatement();
                if (correct) document.getElementById('button_correct').click();
                else document.getElementById('button_wrong').click();
                break;
        }
    });
    function checkStatement(){
        var x = parseInt(document.getElementById("task_x").innerHTML);
        var y = parseInt(document.getElementById("task_y").innerHTML);
        var op = document.getElementById("task_op").innerHTML;
        //var eq = document.getElementById("task_eq").innerHTML;
        var res = parseInt(document.getElementById("task_res").innerHTML);
        var correct = false;
        if ((op === "+") && ((x+y) === res)) correct = true;
        if ((op === "–") && ((x-y) === res)) correct = true;
        if ((op === "×") && ((x*y) === res)) correct = true;
        if ((op === "/") && ((x/y) === res)) correct = true;
        console.log('AI thoughs:  x: '+x+', y: '+y+', op: '+op+', res: '+res, ', correct: '+correct);
        return correct;
    }
})();