阿尔法一站式脚本
// ==UserScript==
// @name 阿尔法一站式脚本
// @namespace http://tampermonkey.net/
// @version 0.1.1
// @description 获取答案并删除注释和空白行且进行输入
// @author ShengMo
// @match https://nuc.alphacoding.cn/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function copy() {
var preElements = document.querySelectorAll('pre.code-solution.overflow-x-auto.select-none');
preElements.forEach(function(pre) {
var code = pre.innerText;
// 删除C语言的单行注释(以 // 开头的注释)
code = code.replace(/\/\/.*$/gm, '');
// 删除C语言的多行注释(以 /* 开始,以 */ 结束的注释)
code = code.replace(/\/\*[\s\S]*?\*\//g, '');
// 删除空白行
code = code.replace(/^\s*[\r\n]/gm, '');
var editor = document.querySelector('.CodeMirror').CodeMirror;
editor.setValue(code);
clickSubmitButton();
});
}
function clickButton() {
var buttons = document.querySelectorAll('button');
buttons.forEach(function(button) {
if(button.textContent.includes('查看答案')) {
button.click();
}
});
setTimeout(copy,100);
}
function clickNextButton() {
var buttons = document.querySelectorAll('button');
buttons.forEach(function(button) {
if(button.textContent.includes('下一项')) {
button.click();
}
});
}
function clickSubmitButton() {
var buttons = document.querySelectorAll('button');
buttons.forEach(function(button) {
if(button.textContent.includes('提交')) {
button.click();
}
});
}
var runButton = document.createElement('button');
runButton.textContent = '一键刷题';
runButton.style.position = 'fixed';
runButton.style.top = '1%';
runButton.style.left = '60%';
runButton.style.zIndex = '9999';
runButton.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
runButton.style.color = '#fff';
runButton.style.border = 'none';
runButton.style.padding = '8px 16px';
runButton.style.borderRadius = '4px';
runButton.addEventListener('click', function() {
setInterval(clickButton, 1 * 1000);
setInterval(clickNextButton, 1000);
});
document.body.appendChild(runButton);
})();