超星学习通考试助手
// ==UserScript==
// @name 超星学习通考试助手
// @namespace speedBoy
// @version 0.0.1
// @description 自动作答学习通考试
// @author speedBoy
// @run-at document-end
// @storageName speedBoy
// @match *://*.chaoxing.com/exam-ans/exam/test/reVersionTestStartNew*
// @match *://*.chaoxing.com/exam-ans/mooc2/exam/preview*
// @match *://*.chaoxing.com/exam/test/reVersionTestStartNew*
// @match *://*.edu.cn/exam-ans/exam/test/reVersionTestStartNew*
// @match *://*.edu.cn/exam/exam-ans/mooc2/exam/preview*
// @match *://*.edu.cn/exam/test/reVersionTestStartNew*
// @match *://*.nbdlib.cn/exam-ans/exam/test/reVersionTestStartNew*
// @match *://*.nbdlib.cn/exam/exam-ans/mooc2/exam/preview*
// @match *://*.nbdlib.cn/exam/test/reVersionTestStartNew*
// @match *://*.hnsyu.net/exam-ans/exam/test/reVersionTestStartNew*
// @match *://*.hnsyu.net/exam/exam-ans/mooc2/exam/preview*
// @match *://*.hnsyu.net/exam/test/reVersionTestStartNew*
// @icon http://pan-yz.chaoxing.com/favicon.ico
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @connect cx.icodef.com
// @license GPL-3.0-or-later
// ==/UserScript==
(()=>{
var token = '';//关注微信公众号:一之哥哥,发送 “token” 领取你的token,填写在两个单引号中间并保存,可以提高答题并发数量。
var _w = unsafeWindow,
_d = _w.document,
_l = _w.location,
_h = _l.href,
_s = Object.fromEntries(new URLSearchParams(_l.search)),
_c = name => `; ${_d.cookie}`.split(`; ${name}=`).pop().split(';').shift(),
_n = function(min,max){
if(arguments.length==1){
max = min+1;
if(min>1){
min = min-1
}
}else if(arguments.length==0){
min = 4;
max = 6;
}
return parseInt(Math.random()*(max-min+1)+min,10)*1000;
};
const courseId = _s['courseid']||_s['courseId'],
classId = _s['classid']||_s['classId']||_s['clazzId']||_s['clazzid'],
types = {'0':'单选题','1':'多选题','2':'填空题','3':'判断题','4':'简答题','5':'名词解释题','6':'论述题','7':'计算题','8':'其它','9':'分录题','10':'资料题','11':'连线题'};
if(_h.includes('reVersionTestStartNew')){
if(_s['newMooc']!='true'){
_l.href = _h+'&newMooc=true';
return;
}
setInterval(function(){
if(typeof _w.topreview == 'function'){
_w.topreview();
}
},_n(3));
return;
}else if(_h.includes('mooc2/exam/preview')){
setInterval(function(){
for(let s of document.getElementsByClassName('mask_div')){
s.remove();
}
},1000);
let questionsElements = _d.getElementsByClassName('questionLi');
var questionNum = questionsElements.length,
finishdQuestionNum = 0,
leftQuestionNum = questionNum,
paperId = _d.getElementById('testPaperId').getAttribute('value'),
waitTime = _n(1,3),
lastClick = new Date().getTime(),
busyThread = 0,
updateStatus = ()=>{
let msg = '交卷';
msg+='(正确率:'+(Math.floor(finishdQuestionNum/questionNum*100))+'%)';
try{
if(leftQuestionNum==0){
msg+=' 作答完成';
}
}catch(e){}
_d.getElementsByClassName('completeBtn')[0].innerHTML = msg;
_d.getElementsByClassName('completeBtn')[0].setAttribute('style','width:200px;');
},
timeClick = (optionE)=>{
if(new Date().getTime()-lastClick<200){
setTimeout(function(){
timeClick(optionE);
},_n(0.1,0.3))
}else{
lastClick = new Date().getTime();
optionE.click();
}
},
ctCallback = function(question,status,res){
busyThread--;
leftQuestionNum--;
try{
_d.getElementById('answerSheet'+question['questionId']).click();
}catch(e){}
if(status){
let hasAnswer = false;
try{
var responseText = res.responseText,
ctResult = JSON.parse(responseText);
}catch(e){
console.log(e);
return;
}
if (ctResult['code'] == -1){
console.log(question['tm']+':未找到答案');
}
let answer = ctResult['data'],
optionsElements = _d.getElementsByClassName('choice'+question['questionId']);
for(let optionE of optionsElements){
let option = optionE.nextElementSibling.innerHTML.replace(/(<([^>]+)>)/ig, '').replace(/^\s+|\s+$/ig,'');
if(question['questionType']<2){
if(option.includes(answer)||answer.includes(option)){
hasAnswer = true;
console.log(question['tm']+':'+answer);
if(!optionE.getAttribute('class').includes('check_answer')){
timeClick(optionE);
}
}else{
if(optionE.getAttribute('class').includes('check_answer')){
timeClick(optionE);
}
}
}else if(question['questionType']==3){
if('正确是对√Tri错误否错×Fwr'.includes(answer)){
hasAnswer = true;
console.log(question['tm']+':'+answer);
if(('正确是对√Tri'.includes(answer)&&option.includes('对'))||('错误否错×Fwr'.includes(answer)&&option.includes('错'))){
if(!optionE.getAttribute('class').includes('check_answer')){
optionE.click();
}
}
}else{
console.log(question['tm']+':未找到答案');
}
}else{
console.log(question['tm']+':暂不支持的题型');
}
}
if(hasAnswer){
finishdQuestionNum++;
}
updateStatus();
}else{
console.log(question['tm']+':查题失败');
}
}
for(let questionElement of questionsElements){
let questionId = questionElement.getAttribute('data')||_d.getElementsByName('questionId'),
questionType = _d.getElementsByName('type'+questionId)[0].getAttribute('value'),
tm = questionElement.getElementsByClassName('mark_name')[0].innerHTML.replace(/(<([^>]+)>)/ig, '').replaceAll(' ',' ').replace(/\d+\.\s*\((.*?),\s\d+\.?\d*分\)\s+/ig,'');
waitTime += _n(4,6);
setTimeout(function(){
let question = {'tm':tm,'questionId':questionId,'questionType':questionType};
busyThread++;
GM_xmlhttpRequest({
method: 'POST',
url: 'https://cx.icodef.com/wyn-nb?v=4',
headers: {
'Content-type': 'application/x-www-form-urlencoded',
'Authorization': token,
},
data: 'question=' + encodeURIComponent(tm) + '&type=' + questionType + '&id=' + paperId,
timeout: 2000,
onload: function(res){
ctCallback(question,true,res);
},
ontimeout:function(){
ctCallback(question,false);
},
onerror: function() {
ctCallback(question,false);
},
});
},waitTime);
}
}
})();