Mathspace Auto Solver

Extracts Mathspace questions and calculates answers

  1. // ==UserScript==
  2. // @name Mathspace Auto Solver
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.0
  5. // @description Extracts Mathspace questions and calculates answers
  6. // @author You
  7. // @match *://*.mathspace.co/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function getQuestionText() {
  15. // Try to find the question text inside the page
  16. let questionElement = document.querySelector('.css-1cs14ul'); // Change this if the selector is different
  17. if (questionElement) {
  18. return questionElement.innerText.trim();
  19. }
  20. return null;
  21. }
  22.  
  23. function solveMathQuestion(question) {
  24. try {
  25. // Replace symbols (if necessary) to ensure JavaScript can evaluate it
  26. let formattedQuestion = question.replace(/×/g, '*').replace(/÷/g, '/');
  27.  
  28. // Use JavaScript's eval() function to calculate the answer
  29. let answer = eval(formattedQuestion);
  30. return answer;
  31. } catch (error) {
  32. console.error("Error calculating the answer:", error);
  33. return "Error";
  34. }
  35. }
  36.  
  37. function displayAnswer() {
  38. let questionText = getQuestionText();
  39.  
  40. if (questionText) {
  41. let answer = solveMathQuestion(questionText);
  42. alert("Correct Answer: " + answer);
  43. console.log("Correct Answer:", answer);
  44. } else {
  45. console.log("Could not find the question.");
  46. }
  47. }
  48.  
  49. // Run the script after a delay to ensure content is loaded
  50. setTimeout(displayAnswer, 3000);
  51. })();
  52.  
  53.