Mathspace Advanced Auto Solver

Extracts, analyzes, solves, and repeats Mathspace questions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Mathspace Advanced Auto Solver
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Extracts, analyzes, solves, and repeats Mathspace questions
// @author       You
// @match        *://*.mathspace.co/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function getQuestionText() {
        // Find the question text on the page
        let questionElement = document.querySelector('.css-1cs14ul'); // Adjust this selector if needed
        if (questionElement) {
            return questionElement.innerText.trim();
        }
        return null;
    }

    function solveMathQuestion(question) {
        try {
            // Replace symbols to JS-compatible format
            let formattedQuestion = question
                .replace(/×/g, '*')  // Convert multiplication
                .replace(/÷/g, '/')  // Convert division
                .replace(/√/g, 'Math.sqrt') // Convert square roots
                .replace(/\^/g, '**'); // Convert exponents

            // Use Function() instead of eval() for better security
            let answer = new Function(`return (${formattedQuestion})`)();
            
            return answer;
        } catch (error) {
            console.error("Error solving the question:", error);
            return "Error";
        }
    }

    function repeatQuestionInInput(question) {
        // Find the input field where answers are entered
        let inputField = document.querySelector('input'); // Adjust selector if needed
        if (inputField) {
            inputField.value = question; // Repeat the question in the input field
            inputField.dispatchEvent(new Event('input', { bubbles: true })); // Simulate typing
        } else {
            console.log("Input field not found.");
        }
    }

    function displayAnswer() {
        let questionText = getQuestionText();

        if (questionText) {
            repeatQuestionInInput(questionText); // Repeat the question
            let answer = solveMathQuestion(questionText);
            
            // Show the correct answer
            alert("Correct Answer: " + answer);
            console.log("Correct Answer:", answer);
        } else {
            console.log("Could not find the question.");
        }
    }

    // Run the script after a delay to ensure content is loaded
    setTimeout(displayAnswer, 3000);
})();