Greasy Fork

Greasy Fork is available in English.

Mathletics Auto Math Solver (Updated)

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 (Updated)
// @namespace    http://greasyfork.org
// @version      1.0
// @description  Automatically solves Mathletics math problems when "A" is pressed.
// @author       YourName
// @match        https://*.mathletics.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

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

    // Function to solve math problems on the page
    function solveMathleticsProblems() {
        // Select the elements that could contain math problems (adjusting the selector as needed)
        const mathProblems = document.querySelectorAll('div.problem, .math-problem, span.problem-text, input.problem-input');

        mathProblems.forEach(problem => {
            let problemText = problem.textContent.trim() || problem.value.trim();

            // Regex to match basic math problems (e.g., 5 + 3)
            const mathRegex = /(\d+)\s*([\+\-\*\/])\s*(\d+)/;

            const match = problemText.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';
                }

                // Display the result next to the problem or input field
                if (problem.tagName === 'INPUT' || problem.tagName === 'TEXTAREA') {
                    // If it's an input or textarea, insert the result
                    problem.value = `${problem.value} = ${result}`;
                } else {
                    // Otherwise, insert the result next to the problem
                    const resultDiv = document.createElement('span');
                    resultDiv.style.fontWeight = 'bold';
                    resultDiv.style.color = 'green';
                    resultDiv.textContent = ` = ${result}`;
                    problem.appendChild(resultDiv);
                }
            }
        });
    }
})();