Universal Math Solver (Auto-fill Answers)

Automatically solves math problems and fills in the answer fields

目前為 2025-05-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Universal Math Solver (Auto-fill Answers)
// @namespace    http://yourdomain.com/
// @version      1.1
// @description  Automatically solves math problems and fills in the answer fields
// @author       You
// @match        *://mathspace.co/*  // Modify this with the correct URL for Mathspace or any other site
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Include the math.js library from a CDN
    const script = document.createElement('script');
    script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjs/10.0.0/math.js';
    script.onload = () => {
        console.log('math.js library loaded');
    };
    document.body.appendChild(script);

    // Function to solve math problems
    function solveMathProblem(problem) {
        try {
            if (problem.startsWith("solve")) {
                // Solve equations like 2x + 3 = 7
                let expr = problem.replace("solve", "").trim();
                let [lhs, rhs] = expr.split("=");
                let equation = math.parse(lhs + '-' + rhs);  // Create an equation
                let solution = math.solve(equation, 'x');  // Solve for x
                return solution[0]; // Return first solution (can be extended for multiple solutions)
            } else if (problem.startsWith("simplify")) {
                // Simplify expressions
                let expr = problem.replace("simplify", "").trim();
                let simplified = math.simplify(expr);
                return simplified.toString();
            } else {
                return "Unsupported problem type.";
            }
        } catch (e) {
            return `Error: ${e}`;
        }
    }

    // Function to fill the answer box on the page
    function fillAnswerBox(answer) {
        const answerBox = document.querySelector('input[type="text"], textarea');  // Adjust selector if necessary
        if (answerBox) {
            answerBox.value = answer;  // Fill the answer box with the solution
            answerBox.dispatchEvent(new Event('input'));  // Trigger input event to update the UI (if required)
            console.log(`Filled the answer box with: ${answer}`);
        } else {
            console.log("Answer box not found.");
        }
    }

    // Example usage: Automatically solve and fill the answer for the problem
    const problem = "solve 2*x + 3 = 7"; // Modify to match the actual problem you want to solve
    const answer = solveMathProblem(problem);
    fillAnswerBox(answer);
})();