Mathspace Auto Hint & Answer

Provides hints and answers on Mathspace.co

As of 2025-02-14. See the latest version.

// ==UserScript==
// @name         Mathspace Auto Hint & Answer
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Provides hints and answers on Mathspace.co
// @author       Your Name
// @match        *://*.mathspace.co/*
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.5.0/math.min.js
// ==/UserScript==

(function() {
    'use strict';

    function getMathQuestion() {
        let questionElement = document.querySelector('.question-text'); // Adjust selector if needed
        return questionElement ? questionElement.innerText.trim() : null;
    }

    function solveMath(question) {
        try {
            return math.evaluate(question); // Uses math.js to calculate
        } catch (e) {
            return "Couldn't process question.";
        }
    }

    function generateHint(question) {
        if (question.includes("+")) return "Think about addition.";
        if (question.includes("-")) return "Consider subtraction.";
        if (question.includes("*")) return "Use multiplication.";
        if (question.includes("/")) return "Try division.";
        return "Break the problem into smaller parts.";
    }

    function displayHintsAndAnswer() {
        let question = getMathQuestion();
        if (!question) return;

        let hint = generateHint(question);
        let answer = solveMath(question);

        let hintBox = document.createElement("div");
        hintBox.style.position = "fixed";
        hintBox.style.bottom = "10px";
        hintBox.style.right = "10px";
        hintBox.style.background = "#fffae5";
        hintBox.style.border = "2px solid #ffaa00";
        hintBox.style.padding = "10px";
        hintBox.style.borderRadius = "5px";
        hintBox.style.boxShadow = "0px 0px 10px rgba(0,0,0,0.1)";
        hintBox.innerHTML = `
            <b>Hint:</b> ${hint} <br>
            <button id="showAnswer">Show Answer</button>
            <div id="answerBox" style="display: none;"><b>Answer:</b> ${answer}</div>
        `;

        document.body.appendChild(hintBox);

        document.getElementById("showAnswer").addEventListener("click", function() {
            document.getElementById("answerBox").style.display = "block";
        });
    }

    // Wait for question to load
    setInterval(displayHintsAndAnswer, 3000);
})();


长期地址
遇到问题?请前往 GitHub 提 Issues。