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, and missing values).

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Mathletics Auto Math Solver
// @namespace    / http://tampermonkey.net
// @version      5.1
// @description  Automatically solves Mathletics math problems when "A" is pressed (supports addition, subtraction, multiplication, and missing values).
// @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"
        if (equation.includes("=")) {
            let parts = equation.split('=');
            let leftPart = parts[0].trim();
            let rightSide = parseInt(parts[1].trim());

            // Check for addition, subtraction, or multiplication with missing value
            if (leftPart.includes("+")) {
                let numbers = leftPart.split("+");
                let leftNumber = parseInt(numbers[0].trim());

                // If right side of the equation is missing, calculate the missing value
                result = rightSide - leftNumber;
            } 
            else if (leftPart.includes("-")) {
                let numbers = leftPart.split("-");
                let leftNumber = parseInt(numbers[0].trim());

                // If right side of the equation is missing, calculate the missing value
                result = leftNumber - rightSide;
            }
            else if (leftPart.includes("×")) {
                let numbers = leftPart.split("×");
                let leftNumber = parseInt(numbers[0].trim());

                // If right side of the equation is missing, calculate the missing value
                result = rightSide / leftNumber;
            }
        } else {
            console.log("Equation format not recognized.");
        }

        if (result !== undefined) {
            console.log("Calculated result:", result);  // For debugging
            // Enter the result into the answer box
            document.getElementsByClassName("questions-input-adjustment questions-input-width-v3")[0].value = result;
        }
    }

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