Greasy Fork is available in English.
Automatically solves Mathletics math problems when "A" is pressed.
当前为
// ==UserScript==
// @name Mathletics Auto Math Solver
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Automatically solves Mathletics math problems when "A" is pressed.
// @author nukerboss
// @match https://*.mathletics.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Listen for the "A" key press to trigger the solving of problems
document.addEventListener('keydown', function (event) {
if (event.key.toLowerCase() === 'a') {
solveMathleticsProblems();
}
});
function solveMathleticsProblems() {
// Find all the input fields or text elements that contain math problems.
const mathProblems = document.querySelectorAll('.problem-text'); // Class name might need adjustment depending on Mathletics HTML structure
mathProblems.forEach(problem => {
const text = problem.textContent.trim();
// Use a regex to identify basic math problems like "5 + 3", "10 * 4"
const mathRegex = /(\d+)\s*([\+\-\*\/])\s*(\d+)/;
const match = text.match(mathRegex);
if (match) {
const num1 = parseFloat(match[1]);
const operator = match[2];
const num2 = parseFloat(match[3]);
let result;
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;
default:
result = 'Error';
}
// Append the result next to the problem
const resultDiv = document.createElement('span');
resultDiv.style.fontWeight = 'bold';
resultDiv.style.color = 'green';
resultDiv.textContent = ` = ${result}`;
// Insert the result into the problem container
problem.appendChild(resultDiv);
}
});
}
})();