Greasy Fork is available in English.
网上学院函数库:自动答题
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/395966/769530/wsxy_handleExams.js
// ==UserScript==
// @name wsxy_handleExams
// @namespace Vionlentmonkey
// @version 0.3
// @description 网上学院函数库:自动答题
// @require http://greasyfork.icu/scripts/395748-wsxy-getdata/code/wsxy_getData.js
// @grant none
// ==/UserScript==
// 首页 - 考试提醒 - 课程考试 - 修改为在新标签页打开
const openExam = async () => {
// 第一页 #courseExam1,第二页 #courseExam2
const exams = document.querySelectorAll('div[id^=courseExam] > a[title]');
for await (let exam of exams) {
const examURL = location.origin + '/sfxzwsxy/' + exam.getAttribute('onclick').split("'")[1];
exam.href = examURL;
exam.onclick = '';
exam.target = '_blank';
}
};
// 首页 - 考试提醒 - 课程考试 - 点击时在新标签页打开对应答案
const addAnswer = async () => {
// 因网络获取与解析需要时间,与 openExam() 整合会造成继发延迟。
const csDataObj = await getCourseData();
const exam_courses = csDataObj.exam_courses;
// 第一页 #courseExam1,第二页 #courseExam2
const exams = document.querySelectorAll('div[id^=courseExam] > a[title]');
for await (let exam of exams) {
const title = exam.getAttribute('title');
for await (let e of exam_courses) {
let course_pk = '';
let answerURL = '';
if (e.course_name === title) {
course_pk = e.course_pk;
answerURL =
location.origin +
'/sfxzwsxy//jypxks/modules/train/course/subject_list.jsp?coursePk=' +
course_pk +
'&op=view';
exam.addEventListener('click', () => {
GM_openInTab(answerURL, true);
GM_notification('答案已同步在隔壁标签页打开。\n暂请考试结束后手动关闭。');
});
}
}
}
};
// 清理“参加考试”链接,新标签页打开考试及答案。
const handelCourseExamList = async exams => {
//const exams = document.querySelectorAll('a[href="#"][onclick^=openWindowFullScreen]');
for (let exam of exams) {
const examURL = location.origin + '/sfxzwsxy/' + exam.getAttribute('onclick').split("'")[1];
exam.href = examURL;
exam.onclick = '';
exam.target = '_blank';
let course_pk = '';
let answerURL = '';
// 在线考试 - 课程考试 iframe
if (examURL.includes('course_pk=')) {
coursePk = examURL.split('course_pk=')[1].split('&')[0];
answerURL =
location.origin +
'/sfxzwsxy//jypxks/modules/train/course/subject_list.jsp?coursePk=' +
coursePk +
'&op=view';
} else if (exam.getAttribute('title')) {
const csDataObj = await getCourseData();
const exam_courses = csDataObj.exam_courses;
const title = exam.getAttribute('title');
for (let e of exam_courses) {
if (e.course_name === title) {
course_pk = String(e.course_pk);
answerURL =
location.origin +
'/sfxzwsxy//jypxks/modules/train/course/subject_list.jsp?coursePk=' +
course_pk +
'&op=view';
}
}
}
exam.addEventListener('click', () => {
GM_openInTab(answerURL, true);
GM_notification('答案已同步在隔壁标签页打开。\n暂请考试结束后手动关闭。');
});
}
};
// 打开考卷后自动答题交卷
const autoExamineTest = async () => {
// 本考试所有试题
let topics = document.getElementsByClassName('topic-tms');
for await (let topic of topics) {
// 题号
let pkid = topic.querySelector('a[pkid]').getAttribute('pkid');
// 本题答案
let subjectDataMap = await getSubjectData(pkid);
// 本题选项
let options = topic.querySelectorAll('.tms-Right-wrong > p > a');
for (let option of options) {
let optionText = option.textContent.trim();
if (subjectDataMap.get('questionType') === '判断题') {
if (option.textContent.trim() === subjectDataMap.get('judgementAnswer')) {
option.click();
}
} else {
// 选择题选项内容带着序号与空格,如“A ”,故获取第三个字符开始的子串
if (subjectDataMap.get(optionText.substring(2)) === '是') {
option.click();
}
}
}
}
// 交卷
if (document.getElementsByClassName('subline _submit').length === 1) {
document.getElementsByClassName('subline _submit')[0].click();
}
// 确认
if (document.getElementsByClassName('layui-layer-btn0').length === 1) {
document.getElementsByClassName('layui-layer-btn0')[0].click();
}
};