适用于阿尔法平台的神秘小代码
我要学Web!!!
更新于 2026.01.05

使用方法:按F12打开浏览器控制台,把下面的代码全部粘贴到浏览器控制台(Console),回车即可。 温馨提示:这段代码是通过查看答案实现的,会影响不查看答案的正确率。请谨慎使用。
(function () {
'use strict';
let running = false;
const sleep = ms => new Promise(res => setTimeout(res, ms));
function decodeHTMLEntities(str) {
return str
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, "'");
}
function hasRunButton() {
return Array.from(document.querySelectorAll('button')).some(btn =>
btn.textContent.includes('运行') || btn.textContent.includes('执行')
);
}
function clickButtonByText(text) {
const btn = Array.from(document.querySelectorAll('button'))
.find(b => b.textContent.includes(text));
if (btn) btn.click();
return !!btn;
}
function clickVideoNext() {
const nodes = Array.from(document.querySelectorAll('span.items-end div'));
const target = nodes.find(el => el.textContent.includes('下一项'));
if (target) {
target.click();
return true;
}
return false;
}
function getPreContent() {
const pre = document.querySelector('pre');
return pre ? pre.innerText : null;
}
function setCodeMirrorValue(code) {
const editor = document.querySelector('.CodeMirror')?.CodeMirror;
if (editor) editor.setValue(code);
}
async function handleCodeQuestion() {
clickButtonByText('查看答案');
await sleep(300);
let code = getPreContent();
if (!code) return;
code = decodeHTMLEntities(code);
const seen = new Set();
code = code.split('\n').filter(l => {
if (seen.has(l)) return false;
seen.add(l);
return true;
}).join('\n');
setCodeMirrorValue(code);
await sleep(200);
clickButtonByText('提交');
await sleep(1500);
clickButtonByText('下一项');
await sleep(800);
}
async function handleNonCodeQuestion() {
if (!clickVideoNext()) {
clickButtonByText('下一项');
}
await sleep(800);
}
async function mainLoop() {
while (running) {
if (hasRunButton()) {
await handleCodeQuestion();
} else {
await handleNonCodeQuestion();
}
}
}
const btn = document.createElement('button');
btn.textContent = '▶ 开始刷题';
btn.style.position = 'fixed';
btn.style.top = '1%';
btn.style.left = '60%';
btn.style.zIndex = '9999';
btn.style.background = 'rgba(0,0,0,0.6)';
btn.style.color = '#fff';
btn.style.border = 'none';
btn.style.padding = '8px 16px';
btn.style.borderRadius = '4px';
btn.style.cursor = 'pointer';
btn.onclick = () => {
running = !running;
btn.textContent = running ? '⏸ 停止刷题' : '▶ 开始刷题';
if (running) mainLoop();
};
document.body.appendChild(btn);
})();
评论
无需登录,审核通过后公开。只有博主可以回复。
正在加载…
已公开的评论