Mathspace Solver (Auto-fill Answers)

Solves Mathspace problems and auto-fills the answer boxes

  1. // ==UserScript==
  2. // @name Mathspace Solver (Auto-fill Answers)
  3. // @namespace http://yourdomain.com/mathspace-solver/
  4. // @version 3.0
  5. // @description Solves Mathspace problems and auto-fills the answer boxes
  6. // @author You
  7. // @match https://mathspace.co/* // This matches all Mathspace pages
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Log to check if the script is running
  15. console.log('Mathspace Solver script loaded');
  16.  
  17. // Include the math.js library for solving problems
  18. const script = document.createElement('script');
  19. script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjs/10.0.0/math.js';
  20. script.onload = () => {
  21. console.log('math.js library loaded');
  22. };
  23. document.body.appendChild(script);
  24.  
  25. // Function to solve math problems
  26. function solveMathProblem(problem) {
  27. console.log(`Solving problem: ${problem}`);
  28. try {
  29. // Clean the problem text by removing non-essential words
  30. let cleanedProblem = problem.replace(/solve|simplify|evaluate|find/g, '').trim();
  31. console.log(`Cleaned Problem: ${cleanedProblem}`);
  32.  
  33. // Solve equations (like 2x + 3 = 7)
  34. if (cleanedProblem.includes("=")) {
  35. let [lhs, rhs] = cleanedProblem.split("=");
  36. lhs = lhs.trim();
  37. rhs = rhs.trim();
  38. console.log(`LHS: ${lhs}, RHS: ${rhs}`);
  39.  
  40. // Create an equation and solve it
  41. let equation = math.parse(lhs + '-' + rhs); // Ensure it is in a solvable form
  42. let solution = math.solve(equation, 'x'); // Solve for x
  43. console.log(`Solution: ${solution[0]}`);
  44. return solution[0]; // Return the first solution
  45. } else {
  46. // Handle other types of problems like simplification
  47. let simplified = math.simplify(cleanedProblem);
  48. console.log(`Simplified: ${simplified}`);
  49. return simplified.toString();
  50. }
  51. } catch (e) {
  52. console.log(`Error solving the problem: ${e}`);
  53. return `Error: ${e}`;
  54. }
  55. }
  56.  
  57. // Function to fill the Mathspace answer box
  58. function fillMathspaceAnswerBox(answer) {
  59. console.log('Attempting to fill answer box...');
  60. const answerBox = document.querySelector('input[type="text"], textarea'); // Assuming input boxes are <input> or <textarea>
  61. // Check if the answer box exists and fill it
  62. if (answerBox) {
  63. answerBox.value = answer; // Fill the answer box with the solution
  64. answerBox.dispatchEvent(new Event('input')); // Trigger input event to notify the page of the change
  65. console.log(`Filled the answer box with: ${answer}`);
  66. } else {
  67. console.log("Answer box not found.");
  68. }
  69. }
  70.  
  71. // Function to detect and solve the problem
  72. function solveCurrentProblem() {
  73. console.log('Checking for problem text...');
  74. const problemText = document.querySelector('.problem-text'); // Find the problem text element (adjust class/ID)
  75. if (problemText) {
  76. const problem = problemText.innerText || problemText.textContent; // Get the problem text
  77. console.log(`Problem detected: ${problem}`);
  78.  
  79. // Solve the problem
  80. const answer = solveMathProblem(problem);
  81.  
  82. // Fill the answer box with the solution
  83. fillMathspaceAnswerBox(answer);
  84. } else {
  85. console.log("Problem text not found.");
  86. }
  87. }
  88.  
  89. // Wait until Mathspace content is fully loaded before running the script
  90. window.addEventListener('load', function() {
  91. console.log('Page fully loaded, running the solver script...');
  92. setTimeout(solveCurrentProblem, 1000); // Add delay to ensure content is fully rendered
  93. });
  94.  
  95. })();

QingJ © 2025

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