Greasy Fork

Greasy Fork is available in English.

Mathletics Auto Math Solver

Automatically solves Mathletics math problems when "A" is pressed.

当前为 2024-11-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Mathletics Auto Math Solver
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Automatically solves Mathletics math problems when "A" is pressed.
// @author       nukerboss
// @match        http://live.mathletics.com/*
// @match        *://live.mathletics.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Listen for the "A" key press to trigger the solving of problems
    document.addEventListener('keydown', function (event) {
        if (event.key.toLowerCase() === 'a') {
            solveMathleticsProblems();
        }
    });

    function solveMathleticsProblems() {
        // Find all the input fields or text elements that contain math problems.
        const mathProblems = document.querySelectorAll('.problem-text'); // Class name might need adjustment depending on Mathletics HTML structure

        mathProblems.forEach(problem => {
            const text = problem.textContent.trim();

            // Use a regex to identify basic math problems like "5 + 3", "10 * 4"
            const mathRegex = /(\d+)\s*([\+\-\*\/])\s*(\d+)/;

            const match = text.match(mathRegex);
            if (match) {
                const num1 = parseFloat(match[1]);
                const operator = match[2];
                const num2 = parseFloat(match[3]);

                let result;
                switch (operator) {
                    case '+':
                        result = num1 + num2;
                        break;
                    case '-':
                        result = num1 - num2;
                        break;
                    case '*':
                        result = num1 * num2;
                        break;
                    case '/':
                        result = num1 / num2;
                        break;
                    default:
                        result = 'Error';
                }

                // Append the result next to the problem
                const resultDiv = document.createElement('span');
                resultDiv.style.fontWeight = 'bold';
                resultDiv.style.color = 'green';
                resultDiv.textContent = ` = ${result}`;

                // Insert the result into the problem container
                problem.appendChild(resultDiv);
            }
        });
    }
})();