MathsSpace AI Solver

Uses AI to solve math problems on MathsSpace.co and display step-by-step solutions.

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         MathsSpace AI Solver
// @namespace    http://mathsspace.co/
// @version      1.0
// @description  Uses AI to solve math problems on MathsSpace.co and display step-by-step solutions.
// @author       CodeCopilot
// @match        *://*.mathsspace.co/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const OPENAI_API_KEY = "YOUR_OPENAI_API_KEY"; // Replace with your API key

    console.log("[MathsSpace AI Solver] Script Loaded ✅");

    function findMathQuestions() {
        let questionNodes = document.querySelectorAll("p, span, div");
        let mathPattern = /(solve|calculate|what is|find the value of)\s*([\d+\-*/().^%]+)/i;

        questionNodes.forEach(node => {
            let text = node.innerText.trim();
            let match = text.match(mathPattern);

            if (match) {
                let expression = match[2];
                solveWithAI(expression, node);
            }
        });
    }

    async function solveWithAI(expression, questionNode) {
        if (questionNode.querySelector(".math-answer")) return; // Prevent duplicate answers

        let answerBox = document.createElement("div");
        answerBox.className = "math-answer";
        answerBox.style.background = "#2196F3";
        answerBox.style.color = "#fff";
        answerBox.style.padding = "8px";
        answerBox.style.marginTop = "5px";
        answerBox.style.borderRadius = "5px";
        answerBox.style.fontWeight = "bold";
        answerBox.innerText = "Solving...";

        questionNode.appendChild(answerBox);

        let response = await fetch("https://api.openai.com/v1/completions", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "Authorization": `Bearer ${OPENAI_API_KEY}`
            },
            body: JSON.stringify({
                model: "gpt-4",
                prompt: `Solve this math problem step-by-step: ${expression}`,
                max_tokens: 100,
                temperature: 0
            })
        });

        let data = await response.json();
        let solution = data.choices[0].text.trim();

        answerBox.innerText = "Solution: " + solution;
    }

    function observeChanges() {
        let observer = new MutationObserver(() => findMathQuestions());
        observer.observe(document.body, { childList: true, subtree: true });
        console.log("[MathsSpace AI Solver] Watching for changes...");
    }

    findMathQuestions();
    observeChanges();
})();