Mathspace Ultimate Solver (Fixed)

Fully automatic Mathspace solver

当前为 2025-02-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Mathspace Ultimate Solver (Fixed)
// @namespace    http://tampermonkey.net/
// @version      6.0
// @description  Fully automatic Mathspace solver
// @author       You
// @match        *://*.mathspace.co/*
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.9.0/math.min.js
// ==/UserScript==

(function() {
    'use strict';

    function waitForElement(selector, callback) {
        const interval = setInterval(() => {
            let element = document.querySelector(selector);
            if (element) {
                clearInterval(interval);
                callback(element);
            }
        }, 500);
    }

    function getQuestionText() {
        let questionElement = document.querySelector('.math-question'); // Ensure this is the correct selector
        if (questionElement) {
            console.log("Question found:", questionElement.innerText);
            return questionElement.innerText.trim();
        }
        console.log("Question not found.");
        return null;
    }

    function formatMathExpression(expression) {
        return expression
            .replace(/×/g, '*')       // Convert multiplication
            .replace(/÷/g, '/')       // Convert division
            .replace(/\^/g, '**')     // Convert exponents
            .replace(/([a-zA-Z])(\d+)/g, '$1^$2')  // Convert "n4" to "n^4"
            .replace(/(\d+)\s*\/\s*(\d+)/g, '($1/$2)'); // Convert fractions
    }

    function solveMathQuestion(expression) {
        try {
            let formattedExpression = formatMathExpression(expression);
            console.log("Formatted Expression:", formattedExpression);
            let answer = math.simplify(formattedExpression).toString();
            console.log("Solved Answer:", answer);
            return answer;
        } catch (error) {
            console.error("Error solving the equation:", error);
            return "Error";
        }
    }

    function insertAnswer(answer) {
        waitForElement('input', (inputField) => { // Wait for input field
            inputField.value = answer;
            inputField.dispatchEvent(new Event('input', { bubbles: true }));
            console.log("Answer inserted:", answer);
            alert("Correct Answer: " + answer);
        });
    }

    function processMathspaceQuestion() {
        let questionText = getQuestionText();
        if (questionText) {
            let answer = solveMathQuestion(questionText);
            insertAnswer(answer);
        }
    }

    setTimeout(processMathspaceQuestion, 3000);
})();