MathsSpace AI Solver

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

  1. // ==UserScript==
  2. // @name MathsSpace AI Solver
  3. // @namespace http://mathsspace.co/
  4. // @version 1.0
  5. // @description Uses AI to solve math problems on MathsSpace.co and display step-by-step solutions.
  6. // @author CodeCopilot
  7. // @match *://*.mathsspace.co/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. const OPENAI_API_KEY = "YOUR_OPENAI_API_KEY"; // Replace with your API key
  15.  
  16. console.log("[MathsSpace AI Solver] Script Loaded ✅");
  17.  
  18. function findMathQuestions() {
  19. let questionNodes = document.querySelectorAll("p, span, div");
  20. let mathPattern = /(solve|calculate|what is|find the value of)\s*([\d+\-*/().^%]+)/i;
  21.  
  22. questionNodes.forEach(node => {
  23. let text = node.innerText.trim();
  24. let match = text.match(mathPattern);
  25.  
  26. if (match) {
  27. let expression = match[2];
  28. solveWithAI(expression, node);
  29. }
  30. });
  31. }
  32.  
  33. async function solveWithAI(expression, questionNode) {
  34. if (questionNode.querySelector(".math-answer")) return; // Prevent duplicate answers
  35.  
  36. let answerBox = document.createElement("div");
  37. answerBox.className = "math-answer";
  38. answerBox.style.background = "#2196F3";
  39. answerBox.style.color = "#fff";
  40. answerBox.style.padding = "8px";
  41. answerBox.style.marginTop = "5px";
  42. answerBox.style.borderRadius = "5px";
  43. answerBox.style.fontWeight = "bold";
  44. answerBox.innerText = "Solving...";
  45.  
  46. questionNode.appendChild(answerBox);
  47.  
  48. let response = await fetch("https://api.openai.com/v1/completions", {
  49. method: "POST",
  50. headers: {
  51. "Content-Type": "application/json",
  52. "Authorization": `Bearer ${OPENAI_API_KEY}`
  53. },
  54. body: JSON.stringify({
  55. model: "gpt-4",
  56. prompt: `Solve this math problem step-by-step: ${expression}`,
  57. max_tokens: 100,
  58. temperature: 0
  59. })
  60. });
  61.  
  62. let data = await response.json();
  63. let solution = data.choices[0].text.trim();
  64.  
  65. answerBox.innerText = "Solution: " + solution;
  66. }
  67.  
  68. function observeChanges() {
  69. let observer = new MutationObserver(() => findMathQuestions());
  70. observer.observe(document.body, { childList: true, subtree: true });
  71. console.log("[MathsSpace AI Solver] Watching for changes...");
  72. }
  73.  
  74. findMathQuestions();
  75. observeChanges();
  76. })();
  77.  
  78.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址