Greasy Fork

来自缓存

Greasy Fork is available in English.

Mathletics Auto Math Solver

Automatically solves Mathletics math problems when "A" is pressed (supports addition, subtraction, multiplication).

当前为 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      4.1
// @description  Automatically solves Mathletics math problems when "A" is pressed (supports addition, subtraction, multiplication).
// @author       nukerboss
// @match        https://*.mathletics.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to solve the equation (addition, subtraction, multiplication, and missing values)
    function solveEquation() {
        // Wait for the question text to be visible
        const questionElement = document.getElementsByClassName('questions-text-alignment whiteTextWithShadow question-size-v4')[0];
        
        if (!questionElement) {
            console.log("Math problem element not found!");
            return;
        }
        
        // Get the equation text
        let equation = questionElement.innerText.trim();
        console.log("Detected equation:", equation);  // For debugging

        let result;

        // Check if the equation is in the format: "X + Y = Z"
        if (equation.includes("=")) {
            let parts = equation.split('=');
            let leftPart = parts[0].trim();
            let rightSide = parseInt(parts[1].trim());
            
            // Handle cases where the equation has a blank (like 7 + _ = 20 or 7 × _ = 20)
            if (leftPart.includes("_")) {
                if (leftPart.includes("+")) {
                    let numbers = leftPart.split("+");
                    let leftNumber = parseInt(numbers[0].trim());
                    result = rightSide - leftNumber;  // Solve for missing number
                } else if (leftPart.includes("-")) {
                    let numbers = leftPart.split("-");
                    let leftNumber = parseInt(numbers[0].trim());
                    result = leftNumber - rightSide;  // Solve for missing number
                } else if (leftPart.includes("×")) {
                    let numbers = leftPart.split("×");
                    let leftNumber = parseInt(numbers[0].trim());
                    result = rightSide / leftNumber;  // Solve for missing multiplier
                }
            } else {
                // Handle standard equations like 7 + 3 = 10
                let equationParts = leftPart.split(" ");
                let firstNum = parseInt(equationParts[0].trim());
                let operator = equationParts[1];
                let secondNum = parseInt(equationParts[2].trim());

                switch (operator) {
                    case "+":
                        result = firstNum + secondNum;
                        break;
                    case "-":
                        result = firstNum - secondNum;
                        break;
                    case "×":
                        result = firstNum * secondNum;
                        break;
                    default:
                        console.log("Unsupported operator:", operator);
                        return;
                }
            }

            // Show the result in the input box
            console.log("Calculated result:", result);  // For debugging
            document.getElementsByClassName("questions-input-adjustment questions-input-width-v3")[0].value = result;
        } else {
            console.log("Equation format not recognized.");
        }
    }

    // Event listener for the "A" key to solve the equation
    window.addEventListener("keydown", function(e) {
        if (e.key === "A" || e.key === "a") {
            solveEquation();
        }
    });
})();