vincentWdp
15 小时 57 分钟前
以下代码是#8 楼的解释. 贴到 console 就好. (再次抱歉☹️):
```
(() => {
window.mathRushBot?.stop?.();
let count = 0;
function calculate(text) {
const normalized = text
.trim()
.replace(/−/g, "-")
.replace(/\s+/g, "");
const match = normalized.match(
/^(-?\d+)([+\-×÷*/])(-?\d+)$/
);
if (!match) return null;
const a = Number(match[1]);
const op = match[2];
const b = Number(match[3]);
switch (op) {
case "+": return a + b;
case "-": return a - b;
case "×":
case "*": return a * b;
case "÷":
case "/": return a / b;
default: return null;
}
}
function answerQuestion() {
const question = document.querySelector("#question");
const input = document.querySelector("#answer");
const feedback = document.querySelector("#feedback");
if (!question || !input || !feedback) return;
if (
input.value !== "" ||
feedback.textContent.trim() !== "按 Enter 提交"
) return;
const answer = calculate(question.textContent);
if (answer === null || !Number.isInteger(answer)) return;
input.value = String(answer);
input.dispatchEvent(
new Event("input", { bubbles: true })
);
input.dispatchEvent(
new KeyboardEvent("keydown", {
key: "Enter",
code: "Enter",
bubbles: true,
cancelable: true
})
);
count++;
}
const timer = setInterval(answerQuestion, 10);
window.mathRushBot = {
get count() {
return count;
},
stop() {
clearInterval(timer);
delete window.mathRushBot;
console.log(`自动答题已停止,共提交 ${count} 题`);
}
};
console.log(
"✅ 自动答题已启动;输入 mathRushBot.stop() 可停止"
);
})();
```