Mathspace Auto Solver & Repeater

Extracts, repeats, and solves Mathspace questions

目前為 2025-02-13 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

(function() {
    'use strict';

    function getQuestionText() {
        // Try to find the question text inside Mathspace
        let questionElement = document.querySelector('.css-1cs14ul'); // Adjust this if needed
        if (questionElement) {
            return questionElement.innerText.trim();
        }
        return null;
    }

    function solveMathQuestion(question) {
        try {
            // Replace math symbols (× to *, ÷ to /) to make it JS-friendly
            let formattedQuestion = question.replace(/×/g, '*').replace(/÷/g, '/');

            // Use JavaScript's eval() to calculate the answer
            let answer = eval(formattedQuestion);
            return answer;
        } catch (error) {
            console.error("Error calculating the answer:", error);
            return "Error";
        }
    }

    function repeatQuestionInInput(question) {
        // Find the answer input field
        let inputField = document.querySelector('input'); // Adjust selector if needed
        if (inputField) {
            inputField.value = question; // Insert the question for repetition
            inputField.dispatchEvent(new Event('input', { bubbles: true })); // Simulate input event
        } else {
            console.log("Input field not found.");
        }
    }

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

        if (questionText) {
            repeatQuestionInInput(questionText); // Repeat the question in input
            let answer = solveMathQuestion(questionText);
            alert("Correct Answer: " + answer); // Show answer in alert
            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);
})();