Mathspace Ultimate Solver

Extracts, analyzes, and correctly solves Mathspace questions

当前为 2025-02-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Mathspace Ultimate Solver
  3. // @namespace http://tampermonkey.net/
  4. // @version 4.0
  5. // @description Extracts, analyzes, and correctly solves Mathspace questions
  6. // @author You
  7. // @match *://*.mathspace.co/*
  8. // @grant none
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.9.0/math.min.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function getQuestionText() {
  16. let questionElement = document.querySelector('[data-testid="question-content"]'); // Adjust if needed
  17. if (questionElement) {
  18. return questionElement.innerText.trim();
  19. }
  20. return null;
  21. }
  22.  
  23. function formatMathExpression(expression) {
  24. return expression
  25. .replace(/×/g, '*') // Convert multiplication
  26. .replace(/÷/g, '/') // Convert division
  27. .replace(/\^/g, '**') // Convert exponents
  28. .replace(/([a-zA-Z])(\d+)/g, '$1^$2') // Convert "n4" to "n^4"
  29. .replace(/(\d+)\s*\/\s*(\d+)/g, '($1/$2)'); // Convert fractions
  30. }
  31.  
  32. function solveMathQuestion(expression) {
  33. try {
  34. let formattedExpression = formatMathExpression(expression);
  35. let answer = math.simplify(formattedExpression).toString();
  36. return answer;
  37. } catch (error) {
  38. console.error("Error solving the equation:", error);
  39. return "Error";
  40. }
  41. }
  42.  
  43. function displayAnswer() {
  44. let questionText = getQuestionText();
  45.  
  46. if (questionText) {
  47. console.log("Extracted Question:", questionText); // Debugging
  48. let answer = solveMathQuestion(questionText);
  49. alert("Correct Answer: " + answer);
  50. console.log("Correct Answer:", answer);
  51. } else {
  52. console.log("Could not find the question.");
  53. }
  54. }
  55.  
  56. setTimeout(displayAnswer, 3000);
  57. })();
  58.  
  59.