Greasy Fork is available in English.
继续教育公需科目专业科目辅助|自动答题|
当前为
// ==UserScript==
// @name 济南专业技师人员继续教育
// @namespace Violentmonkey Scripts
// @match *://*.ghlearning.com/*
// @match http://221.214.69.254:9091/*
// @grant none
// @version 0.1.0
// @author aliha
// @description 继续教育公需科目专业科目辅助|自动答题|
// @run-at document-end
// ==/UserScript==
(function () {
function delay(s) {
return new Promise(resolve => setTimeout(resolve, s * 1000));
}
// 检测答题元素,获取选项
function getItems() {
if (document.querySelector(".pv-ask-modal")) {
let qusCard = document.querySelector(".pv-ask-modal")
let inputs = qusCard.querySelectorAll("input")
return inputs
}
return null
}
// 生成数组所有的穷举组合并剔除空数组
function generateCombinations(arr) {
const combinations = [[]];
// 遍历数组元素
for (let i = 0; i < arr.length; i++) {
const currentLength = combinations.length;
// 遍历当前已生成的组合
for (let j = 0; j < currentLength; j++) {
const currentCombination = combinations[j];
// 生成新的组合,包含当前数组元素
const newCombination = currentCombination.concat(arr[i]);
// 如果组合不为空,则将新组合添加到二维数组中
if (newCombination.length > 0) {
combinations.push(newCombination);
}
}
}
// 剔除空数组
return combinations.filter(combination => combination.length > 1);
}
// 挨个尝试,检测到回答错误继续,检测到回答正确跳出,同时清空答案
async function answer(res_ls) {
let flag = false;
for (let i = res_ls.length - 1; i != 0; i--) {
await delay(6)
let inputs = getItems()
console.log(`尝试第${res_ls.length - i}次作答`)
console.log(res_ls[i])
for (let j = 0; j < res_ls[i].length; j++) {
try{
inputs[res_ls[i][j]].checked = true
}catch(err){
flag = true;
break
}
}
if(flag){
break;
}
// 提交答案,正确跳出循环,错误继续尝试
let button = document.querySelector('button.pv-ask-submit[data-type="pvSubmit"]');
await delay(1)
button.click()
}
}
// 主函数
async function main() {
console.log("开始答题")
if (getItems()) {
let inputs = getItems()
const array = Array.from({ length: inputs.length }, (_, index) => index);
let num = generateCombinations(array)
await answer(num)
console.log("答题脚本执行完毕")
} else {
console.log("未检测到答题卡,答题脚本执行完毕")
}
}
setInterval(main, 300000);
})();