Spark Maths Auto Solver

Solves Spark Maths questions using WolframAlpha

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Spark Maths Auto Solver
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Solves Spark Maths questions using WolframAlpha
// @author       Your Name
// @match        *://*.sparkmaths.com/*  // Adjust if needed
// @grant        GM_xmlhttpRequest
// @connect      api.wolframalpha.com
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    const WOLFRAM_API_KEY = "EP3QKE-3YL22GEG55";  // Your API key

    function getMathSolution(question, callback) {
        const query = encodeURIComponent(question);
        const apiUrl = "https://api.wolframalpha.com/v2/query?input=" + query + 
                       "&format=plaintext&output=JSON&appid=" + WOLFRAM_API_KEY;

        GM_xmlhttpRequest({
            method: "GET",
            url: apiUrl,
            onload: function(response) {
                try {
                    var data = JSON.parse(response.responseText);
                    if (data.queryresult.success) {
                        var answer = (data.queryresult.pods && data.queryresult.pods[1] &&
                                      data.queryresult.pods[1].subpods &&
                                      data.queryresult.pods[1].subpods[0] &&
                                      data.queryresult.pods[1].subpods[0].plaintext) || "No answer found";
                        callback(answer);
                    } else {
                        callback("WolframAlpha couldn't solve this.");
                    }
                } catch (error) {
                    callback("Error fetching the solution.");
                }
            }
        });
    }

    function findMathQuestions() {
        var questions = document.querySelectorAll(".question-text"); // Adjust selector if needed
        questions.forEach(function(questionElement) {
            var questionText = questionElement.innerText.trim();
            getMathSolution(questionText, function(answer) {
                var answerDiv = document.createElement("div");
                answerDiv.style.color = "green";
                answerDiv.style.fontWeight = "bold";
                answerDiv.innerText = "Answer: " + answer;
                questionElement.appendChild(answerDiv);
            });
        });
    }

    setTimeout(findMathQuestions, 3000); // Wait for page to load
})();