Mathspace Advanced Auto Solver

Extracts, analyzes, solves, and repeats Mathspace questions

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

  1. // ==UserScript==
  2. // @name Mathspace Advanced Auto Solver
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.0
  5. // @description Extracts, analyzes, solves, and repeats Mathspace questions
  6. // @author You
  7. // @match *://*.mathspace.co/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function getQuestionText() {
  15. // Find the question text on the page
  16. let questionElement = document.querySelector('.css-1cs14ul'); // Adjust this selector if needed
  17. if (questionElement) {
  18. return questionElement.innerText.trim();
  19. }
  20. return null;
  21. }
  22.  
  23. function solveMathQuestion(question) {
  24. try {
  25. // Replace symbols to JS-compatible format
  26. let formattedQuestion = question
  27. .replace(/×/g, '*') // Convert multiplication
  28. .replace(/÷/g, '/') // Convert division
  29. .replace(/√/g, 'Math.sqrt') // Convert square roots
  30. .replace(/\^/g, '**'); // Convert exponents
  31.  
  32. // Use Function() instead of eval() for better security
  33. let answer = new Function(`return (${formattedQuestion})`)();
  34. return answer;
  35. } catch (error) {
  36. console.error("Error solving the question:", error);
  37. return "Error";
  38. }
  39. }
  40.  
  41. function repeatQuestionInInput(question) {
  42. // Find the input field where answers are entered
  43. let inputField = document.querySelector('input'); // Adjust selector if needed
  44. if (inputField) {
  45. inputField.value = question; // Repeat the question in the input field
  46. inputField.dispatchEvent(new Event('input', { bubbles: true })); // Simulate typing
  47. } else {
  48. console.log("Input field not found.");
  49. }
  50. }
  51.  
  52. function displayAnswer() {
  53. let questionText = getQuestionText();
  54.  
  55. if (questionText) {
  56. repeatQuestionInInput(questionText); // Repeat the question
  57. let answer = solveMathQuestion(questionText);
  58. // Show the correct answer
  59. alert("Correct Answer: " + answer);
  60. console.log("Correct Answer:", answer);
  61. } else {
  62. console.log("Could not find the question.");
  63. }
  64. }
  65.  
  66. // Run the script after a delay to ensure content is loaded
  67. setTimeout(displayAnswer, 3000);
  68. })();
  69.  
  70.