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      2.0
// @description  Automatically solves Mathletics math problems when "A" is pressed.
// @author       nukerboss
// @match        https://*.mathletics.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    
    // Function to solve addition, subtraction, and multiplication equations
    function solveEquation() {
        var equation = document.getElementsByClassName('questions-text-alignment whiteTextWithShadow question-size-v4')[0].innerText.trim();
        var result;

        if (equation.includes("=")) {
            var equationParts = equation.split('=');
            var leftPart = equationParts[0].trim();
            var rightSide = parseInt(equationParts[1].trim());

            if (leftPart.includes("_")) {
                // Solve for blank space in the equation
                if (leftPart.includes("+")) {
                    var parts = leftPart.split("+");
                    var leftNumber = parseInt(parts[0].trim());
                    result = rightSide - leftNumber;
                } else if (leftPart.includes("-")) {
                    var parts = leftPart.split("-");
                    var leftNumber = parseInt(parts[0].trim());
                    result = leftNumber - rightSide;
                } else if (leftPart.includes("×")) {
                    var parts = leftPart.split("×");
                    var leftNumber = parseInt(parts[0].trim());
                    result = rightSide / leftNumber;
                }
            } else {
                // Handle standard equations
                var parts = leftPart.split(" ");
                var firstNum = parseInt(parts[0].trim());
                var operator = parts[1];
                var secondNum = parseInt(parts[2].trim());

                switch (operator) {
                    case "+":
                        result = firstNum + secondNum;
                        break;
                    case "-":
                        result = firstNum - secondNum;
                        break;
                    case "×":
                        result = firstNum * secondNum;
                        break;
                }
            }

            // Display the result
            document.getElementById("dashow").innerText = result;
            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();
        }
    });
})();