Mathspace Ultimate Solver

Extracts, analyzes, and correctly solves Mathspace questions

Από την 13/02/2025. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Mathspace Ultimate Solver
// @namespace    http://tampermonkey.net/
// @version      4.0
// @description  Extracts, analyzes, and correctly solves Mathspace questions
// @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 getQuestionText() {
        let questionElement = document.querySelector('[data-testid="question-content"]'); // Adjust if needed
        if (questionElement) {
            return questionElement.innerText.trim();
        }
        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);
            let answer = math.simplify(formattedExpression).toString();
            return answer;
        } catch (error) {
            console.error("Error solving the equation:", error);
            return "Error";
        }
    }

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

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

    setTimeout(displayAnswer, 3000);
})();