JavaScript——易班优课YOOC课群在线测试自动答题解决方案(五)简单插件
前文
JavaScript——易班优课YOOC课群在线测试自动答题解决方案(一)答案获取
Spring Boot——易班优课YOOC课群在线测试自动答题解决方案(二)答案储存
Spring Boot——易班优课YOOC课群在线测试自动答题解决方案(三)答案查询
JavaScript——易班优课YOOC课群在线测试自动答题解决方案(四)答案显示
解决方案
// ==UserScript==
// @name YOOC Exam
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author STZG
// @match https://www.yooc.me/group/*/exam/*/detail
// @grant none
// ==/UserScript==(function() {'use strict';// Your code here...
var examUpload=()=>{var xmlhttp = new XMLHttpRequest();//获取对象xmlhttp.onreadystatechange = function(){//设置回调函数if(xmlhttp.readyState == 4){//这里的4是请求的状态码,代表请求已经完成if(xmlhttp.status == 200 || xmlhttp.status == 304){//这里是获得响应的状态码,200代表成功,304代表无修改可以直接从缓存中读取console.log(xmlhttp);//创建DOMvar html=document.createElement("html");html.innerHTML=xmlhttp.responseTextconsole.log(html)//获取考试信息var group=document.getElementById('group-data')var groupId=group.getAttribute("data-group-id")var examId=group.getAttribute("data-exam-id")//获取问题信息var question=Array.from(html.getElementsByClassName('question-board'))console.log(question)//数据封装var question_arr=[]question.forEach(q=>{question_arr.push({id:q.id,question:q.outerHTML.replace('/the-ans fls/g',"the-ans crt").replace('/{//获取考试信息var group=document.getElementById('group-data')var groupId=group.getAttribute("data-group-id")var examId=group.getAttribute("data-exam-id")//获取问题信息questions=document.getElementsByClassName('question-board')var question_arr=[]Array.from(questions).forEach(q=>{question_arr.push(q.id.substr(9))})var xmlhttp = new XMLHttpRequest();//获取对象xmlhttp.onreadystatechange = function(){//设置回调函数if(xmlhttp.readyState == 4){//这里的4是请求的状态码,代表请求已经完成if(xmlhttp.status == 200 || xmlhttp.status == 304){//这里是获得响应的状态码,200代表成功,304代表无修改可以直接从缓存中读取var result = xmlhttp.responseText;//这里获取的是响应文本,也可以获得响应xml或JSONconsole.log(result)//解析为JS对象var obj = JSON.parse(result);var questionContainer=document.getElementsByClassName('exam-detial-container')[0]obj.forEach(q=>{var question=document.getElementById('question-'+q.id)var answer = document.createElement("div");answer.innerHTML = q.question;var child=answer.childNodes[0]child.id='ans-'+q.idquestionContainer.insertBefore(child,question)console.log(question)console.log(answer)})}}}xmlhttp.open("GET","https://localhost/MyZSTU/yooc/group/"+groupId+"/exam/"+examId+"/answer?question="+question_arr);xmlhttp.send();//GET请求
}//获取考试信息
var group=document.getElementById('group-data')
var groupId=group.getAttribute("data-group-id")
var examId=group.getAttribute("data-exam-id")
var examQuestionNum=Number(group.getAttribute("data-questions"))
//获取问题信息
var questions=document.getElementsByClassName('question-board')
var questionNum = questions.length
//获取答案信息
var ansElements = document.getElementsByClassName('the-ans')
var ansNum = ansElements.length
if(ansNum>0){if(questionNum===examQuestionNum){examUpload()}else{console.log("现在是考试中,不能上传答案哦。")}
}else{answer()
}})();
使用教程


参考文章
https://www.jianshu.com/p/cf3f8d20bbfc
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
