Zetamac

try to take over the world!

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Zetamac
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  try to take over the world!
// @author       You
// @match        https://arithmetic.zetamac.com/game*
// @grant        none
// @require http://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==


var input = document.getElementsByClassName("answer")[0];
var character = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()`~-_=+[{]} \\ |;: \' \" ,<.>/?", number = "0123456789";

function isNumber(num) {
    for(let j = 0; j < 10; j++) {
        if(num == number.charAt(j)) return true;
    }
    return false;
}

function isChar(char) {
    for(var i = 0; i < character.length; i++) {
        if(char === character[i]) return true;
    }
    return false;
}

function parse() {
    var problem = document.getElementsByClassName("problem")[0].innerHTML;
    var n = 0, m = 0, ans, operator, reached = false;
    for(let i = 0; i < problem.length; i++) {
        var char = problem.charAt(i);
        switch(char) {
            case '+':
                operator = '+';
                reached = true;
                break;
            case '–':
                operator = '–';
                reached = true;
                break;
            case '×':
                operator = '×';
                reached = true;
                break;
            case '÷':
                operator = '÷'
                reached = true;
        }
        if(!isNumber(char)) continue;
        if(reached) m = 10 * m + (char - '0');
        else n = 10 * n + (char - '0');
    }
    switch(operator) {
        case '+':
            ans = n + m;
            break;
        case '–':
            ans = n - m;
            break;
        case '×':
            ans = n * m;
            break;
        case '÷':
            ans = n / m;
    }
    return ans.toString();
}

function checkDelete(key) {
    if(key === "Backspace" || key == "Delete") {
        if(input.value[input.value.length - 1] === undefined) return true;
        if(input.value.length != 0) input.value = input.value.slice(0, -1);
        return false;
    }
}

const sleepNow = (delay) => new Promise((resolve) => setTimeout(resolve, delay))
async function display(ans) {
    for (let i = 0; i < ans.length; i++) {
        await sleepNow(75);
        input.value += String(ans.charAt(i));
    }
}

(function() {
    input.addEventListener("keydown",
    function(e) {
        e.preventDefault();
        const key = e.key;
        if(checkDelete(key) || !isChar(key)) return;
        var ans = parse();
        input.value = ans;
        // display(ans)
    } );
})();