Spark Maths Auto Solver

Solves Spark Maths questions using WolframAlpha

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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
})();