不知名系列-继续教育 安徽继续教育在线(请看附加信息)
// ==UserScript==
// @name 不知名系列-继续教育 安徽继续教育在线(请看附加信息)
// @namespace http://tampermonkey.net/
// @version 2024.06.02
// @description 如需代替看视频请添加微信:bzm8866999
// @author 不知名打工仔
// @match https://main.ahjxjy.cn/study/*
// @match http://www.ahjxjy.cn/study/html/content/sxsk/*
// @match http://www.ahjxjy.cn/study/html/content/studying/*
// @require https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js
// @grant GM_log
// @grant GM_notification
// @grant GM_getValue
// @grant GM_setValue
// @grant unsafeWindow
// ==/UserScript==
// 说明
// 链接格式
// 在线作业: http://www.ahjxjy.cn/study/html/content/studying/?courseOpenId=nl6waows-irps8zsjcrqaq&cellId=7epbaeysrr1cgsazgdk-1q&schoolCode=026#type=comment
// 答案页: http://www.ahjxjy.cn/study/html/content/studying/?courseOpenId=nl6waows-irps8zsjcrqaq&cellId=7epbaeysrr1cgsazgdk-1q&schoolCode=026#type=comment
// 考试页: http://www.ahjxjy.cn/study/html/content/sxsk/?courseOpenId=1yaxaowslkzokvr3qu-xza&schoolCode=026
// 考试答案页: http://www.ahjxjy.cn/study/html/content/sxsk/?courseOpenId=1yaxaowslkzokvr3qu-xza&schoolCode=026
unsafeWindow.alert = function(){return false};
window.alert = function(){return false};
Window.prototype.alert = function(){return false};
unsafeWindow.confirm = function(){return true};
window.confirm = function(){return true};
Window.prototype.confirm = function(){return true};
var flags = document.getElementsByClassName('e-selects-g')
if(flags.length < 1){
setInterval(function(){
var current_video = document.querySelector('video')
if(current_video){
if (current_video.ended == false) {
var durations = document.querySelector('video').duration
document.querySelector('video').currentTime = durations
}
if (document.getElementsByClassName('btn btn-green')) {
document.getElementsByClassName('btn btn-green')[0].click()
}
}else{
if (document.getElementsByClassName('preNext next').length > 0){
if (document.getElementsByClassName('preNext next')[0].title == '下一单元'){
document.getElementsByClassName('preNext next')[0].style == 'opacity: 0.3; display: block;'
document.getElementsByClassName('preNext next')[0].click()
}
}
}
},5000)
}
(function() {
// -----------------
// 全局配置
// -----------------
var current_url = window.location.href;
// -----------------
// 自动处理逻辑
// -----------------
// -----------------
// 公共函数
// -----------------
function getPageName() {
if (current_url.indexOf('content/studying') != -1) {
return "homework";
} else if (current_url.indexOf('content/sxsk') != -1) {
return "exam";
} else {
return "other";
}
}
//自动刷课时
var confirm = function () {
return true;
};
window.confirm = function () {
return true;
};
/**
* 在线作业开始
**/
function doHomework() {
document.getElementById("autoExam").hidden = true;
(async () => {
await wait(5000);
tryToAnswer();
collectAnswers();
})();
}
// 收集答案
function doExam() {
let btns = document.querySelectorAll(".e-save>a");
console.log(btns);
console.log('======================')
if (btns.length == 0|| (btns && btns[0] && btns[0].textContent == "重做")) {
console.log("已确认,目前在错题答案页");
}
// 逐一收集答案
let questions = document.querySelectorAll(".e-q");
for (let question of questions) {
let title = question.querySelector(".e-q-q").textContent.trim();
try {
// 问答题
let answers = question.querySelector(".e-ans-r").textContent.trim();
if (!GM_getValue(title, "")) {
console.log("save question answer: " + title);
GM_setValue(title, answers)
}
} catch (e) {
continue
}
}
(async () => {
await wait(3000);
btns[0].click();
SubmitForCollectAnswers()
})();
}
/**
* 需要等待考题出现,因为前面要开摄像头
**/
function tryToExam() {
// 逐一收集答案
(async () => {
let questions = document.querySelectorAll(".e-q");
console.log("考题总数: " + questions.length);
for (let question of questions) {
let title = question.querySelector(".e-q-q").textContent.trim();
let options = question.querySelectorAll(".e-a");
let answers = GM_getValue(title, "");
console.log("title: " + title);
console.log("answers: " + answers);
if (answers) {
var answerIndexs = convertAnswersToIndex(answers);
console.log(answerIndexs);
for (let answer_index of answerIndexs) {
options[answer_index].click();
await wait(500);
}
}else {
if (question.querySelector(".e-blank-e")) {
throw new Error("Stopped JavaScript.");
}
}
}
doExam()
})();
}
/**
* 尝试答题
**/
function tryToAnswer() {
let noAnswerQuestionCounter = 0; // 找不到答案的题目数量
let btns = document.querySelectorAll(".e-save>a");
if (btns.length != 1 || btns[0].textContent == '重做') {
console.log("已确认,非一个按钮,目前不在答题页");
console.log("退出运行");
return;
}
console.log("已确认,一个按钮,目前在答题页");
// 逐一收集答案
(async () => {
let questions = document.querySelectorAll(".e-q");
for (let question of questions) {
let title = question.querySelector(".e-q-q").textContent.trim();
let options = question.querySelectorAll(".e-a");
let answers = GM_getValue(title, "");
console.log("title: " + title);
console.log("answers: " + answers);
if (answers) {
var answerIndexs = convertAnswersToIndex(answers);
console.log(answerIndexs);
for (let answer_index of answerIndexs) {
options[answer_index].click();
await wait(500);
}
} else {
noAnswerQuestionCounter += 1;
if (question.querySelector(".e-blank-e")) {
throw new Error("Stopped JavaScript.");
}
}
}
SubmitForCollectAnswers();
})();
}
/**
* 提交,为了收集答案
*
* 通过提交来获取
* - 点击提交按钮
**/
function SubmitForCollectAnswers() {
document.querySelector("div.e-save>a").click(); // 提交答案
(async () => {
await wait(3000);
document.querySelectorAll(".ui-MDialog-bottom>button")[0].click(); // 保存最高分
})();
}
function collectAnswers() {
let btns = document.querySelectorAll(".e-save>a");
if (btns.length != 2 && btns[0].textContent != "重做") {
console.log("已确认,非两个按钮,目前不在错题答案页");
console.log("退出运行");
return;
}
var currentLi
console.log("已确认,两个按钮,目前在错题答案页");
if (parseInt(document.querySelector(".totalscore em").textContent.trim()) >= 90) {
document.getElementsByClassName('sectionlist btn_dropdown')[0].click()
setInterval(function(){
var li_list = document.getElementsByTagName('li')
for (var i = 0; i < li_list.length; i++) {
if(li_list[i].className == 'current') {
currentLi = i
console.log('i',i)
}
}
li_list[currentLi+3].getElementsByTagName('a')[0].click()
li_list('li')[currentLi+4].getElementsByTagName('a')[0].click()
},2000)
return;
}
// 逐一收集答案
let questions = document.querySelectorAll(".e-q");
for (let question of questions) {
let title = question.querySelector(".e-q-q").textContent.trim();
try {
// 问答题
let answers = question.querySelector(".e-ans-r").textContent.trim();
if (!GM_getValue(title, "")) {
console.log("save question answer: " + title);
GM_setValue(title, answers)
}
} catch (e) {
continue
}
}
(async () => {
await wait(3000);
if (btns.length == 2) {
btns[1].click();
} else {
btns[0].click();
}
})();
}
/*
* document.querySelector(".positiveSolution").textContent
* "【答案】C "
*
* document.querySelector(".positiveSolution").textContent.trim().split("】")[1]
* "C"
*
* 选择:
* document.querySelectorAll(".question-option .mark")[3].click()
*
* 提交:
* document.querySelectorAll("button.ivu-btn-primary")[0].click()
*
* 关闭,同上:
* document.querySelectorAll("button.ivu-btn-primary")[0].click()
*/
function answerQuestion() {
let answers = document.querySelector(".positiveSolution").textContent.trim().split("】")[1];
let numAnswers = convertAnswersToIndex(answers);
for (let index of numAnswers) {
document.querySelectorAll(".question-option .mark")[index].click()
}
(async () => {
// 提交
await wait(1000);
document.querySelectorAll("button.ivu-btn-primary")[0].click()
// 关闭
await wait(1000);
document.querySelectorAll("button.ivu-btn-primary")[0].click()
})();
}
function convertAnswersToIndex(answers) {
let numAnswers = [];
for (let item of answers.split("、")) {
if (!item) {
continue;
}
if (item == 'A' || item == '正确') {
numAnswers.push(0);
} else if (item == 'B' || item == '错误') {
numAnswers.push(1);
} else if (item == 'C') {
numAnswers.push(2);
} else if (item == 'D') {
numAnswers.push(3);
} else if (item == 'E') {
numAnswers.push(4);
} else if (item == 'F') {
numAnswers.push(5);
}
}
return numAnswers;
}
function wait(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log("Done waiting");
resolve(ms)
}, ms)
})
}
function addStatusBoard() {
$(
'<div style="border: 2px dashed rgb(149, 252, 251); width: 330px; height: 9em; position: fixed; bottom: 0; right: 0; z-index: 99999; background-color: #f2f2f2; overflow-x: auto; padding: 1em;">' +
'<div>' +
'<h2>自动答题</h2>' +
'<div id="tm_status" style="margin-top: 1em;"></div>' +
'</div>' +
'<div style="margin-top: 1em;"><button id="autoExam" style="color: #fff; background-color: #28a745; border-color: #28a745; padding: 0.2rem 0.4rem;">开始自动考试</button></div>' +
'</div>'
).appendTo("body");
}
/*
* <span tabindex="0" class="ivu-switch ivu-switch-checked ivu-switch-default"><input type="hidden" value="true"> <span class="ivu-switch-inner"><span>开</span> <!----></span></span>
*
* document.querySelectorAll(".ivu-switch")
*/
function enableAutoPlayVideoList() {
}
})();