當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JavaScript——易班优课YOOC课群在线测试自动答题解决方案(十二)脚本整合
生活随笔
收集整理的這篇文章主要介紹了
JavaScript——易班优课YOOC课群在线测试自动答题解决方案(十二)脚本整合
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
前文
JavaScript——易班優(yōu)課YOOC課群在線測試自動答題解決方案(一)答案獲取
Spring Boot——易班優(yōu)課YOOC課群在線測試自動答題解決方案(二)答案儲存
Spring Boot——易班優(yōu)課YOOC課群在線測試自動答題解決方案(三)答案查詢
JavaScript——易班優(yōu)課YOOC課群在線測試自動答題解決方案(四)答案顯示
JavaScript——易班優(yōu)課YOOC課群在線測試自動答題解決方案(五)簡單腳本
Spring Boot——易班優(yōu)課YOOC課群在線測試自動答題解決方案(六)后端改造
JavaScript——易班優(yōu)課YOOC課群在線測試自動答題解決方案(七)隨機(jī)答案
JavaScript——易班優(yōu)課YOOC課群在線測試自動答題解決方案(八)功能面板
JavaScript——易班優(yōu)課YOOC課群在線測試自動答題解決方案(九)ID標(biāo)簽
Vue + Element UI + Spring Boot——易班優(yōu)課YOOC課群在線測試自動答題解決方案(十)問題管理頁面
JavaScript——易班優(yōu)課YOOC課群在線測試自動答題解決方案(十一)恢復(fù)右鍵、選擇和復(fù)制
解決方案
// ==UserScript== // @name YOOC Exam Detail // @namespace http://tampermonkey.net/ // @version 0.2 // @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(){//設(shè)置回調(diào)函數(shù)if(xmlhttp.readyState == 4){//這里的4是請求的狀態(tài)碼,代表請求已經(jīng)完成if(xmlhttp.status == 200 || xmlhttp.status == 304){//這里是獲得響應(yīng)的狀態(tài)碼,200代表成功,304代表無修改可以直接從緩存中讀取console.log(xmlhttp);//創(chuàng)建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)//數(shù)據(jù)封裝var question_arr=[]question.forEach(q=>{question_arr.push({id:q.id,question:q.outerHTML.replace(/the-ans fls/g,"the-ans crt").replace(/<li class="crt"/g,'<li class=""').replace(/<li class="fls"/g,'<li class=""')})document.getElementById(q.id).getElementsByClassName('the-ans')[0].innerHTML=q.getElementsByClassName('the-ans')[0].innerHTML })//上傳服務(wù)器var posthttp = new XMLHttpRequest();//獲取對象posthttp.onreadystatechange = function(){//設(shè)置回調(diào)函數(shù)if(posthttp.readyState == 4){//這里的4是請求的狀態(tài)碼,代表請求已經(jīng)完成if(posthttp.status == 200 || posthttp.status == 304){//這里是獲得響應(yīng)的狀態(tài)碼,200代表成功,304代表無修改可以直接從緩存中讀取var result = posthttp.responseText;//這里獲取的是響應(yīng)文本,也可以獲得響應(yīng)xml或JSONconsole.log(result)}}}posthttp.open("POST","https://locahost/group/"+groupId+"/exam/"+examId+"/upload");//JSON Headerposthttp.setRequestHeader("Content-Type","application/json");posthttp.setRequestHeader("Content-Security-Policy","upgrade-insecure-requests");//解析為JSONposthttp.send(JSON.stringify(question_arr));//POST請求}}}xmlhttp.open("GET",document.URL);xmlhttp.send();//GET請求 } var answer=()=>{//獲取考試信息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(){//設(shè)置回調(diào)函數(shù)if(xmlhttp.readyState == 4){//這里的4是請求的狀態(tài)碼,代表請求已經(jīng)完成if(xmlhttp.status == 200 || xmlhttp.status == 304){//這里是獲得響應(yīng)的狀態(tài)碼,200代表成功,304代表無修改可以直接從緩存中讀取var result = xmlhttp.responseText;//這里獲取的是響應(yīng)文本,也可以獲得響應(yīng)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='answer-'+q.idquestionContainer.insertBefore(child,question)console.log(question)console.log(answer)})addIdTag()}}}xmlhttp.open("GET","https://locahost/group/yooc/group/"+groupId+"/exam/"+examId+"/answer?question="+question_arr);xmlhttp.send();//GET請求 } var nullSubmit=()=>{//獲取問題信息var question=Array.from(document.getElementsByClassName('question-board'))question.forEach(q=>{console.log(q)let inputTag=q.getElementsByTagName('input')console.log(inputTag)if(inputTag.length>0){let Ele=inputTag[0]if(Ele.type==="radio"||Ele.type==="checkbox"){if(Ele.type==="radio"){Ele.checked=true;}else if(Ele.type==="checkbox"){Ele.checked=true;}//頁面方法choiceAnswerData($(q))}else if(Ele.type==="text"){let Eles=Array.from(inputTag)Eles.forEach(e=>{e.value="test"})//頁面方法inputAnswerData($(q))}let ele_name=Ele.name.replace(/\_[0-9]+/, '')let questionTag=document.getElementById(ele_name)questionTag.classList.add('done')}}) } var appendsomething=()=>{var releaseButtun=document.getElementsByClassName('release-board')[0]var ns=document.createElement('a')ns.id="null-submit"ns.href="javascript:;"ns.innerText="提交白卷"ns.style="margin-left: 0px;margin-top: 10px;"ns.title="隨機(jī)答案提交試卷"ns.onclick=()=>{nullSubmit()//頁面方法xAlert('提示','隨機(jī)答案選擇完畢,可以提交了')}releaseButtun.appendChild(ns)var qa=document.createElement('a')qa.id="query-answer"qa.href="javascript:;"qa.innerText="查詢答案"qa.style="margin-left: 20px;margin-top: 10px;"qa.title="云端題庫查詢答案"qa.onclick=()=>{var ansElements = document.getElementsByClassName('the-ans')var ansNum = ansElements.lengthif(ansNum<0){answer()}else{//頁面方法xAlert('失敗','已經(jīng)有答案了哦')}}releaseButtun.appendChild(qa) } var addIdTag=()=>{//獲取問題信息var question=Array.from(document.getElementsByClassName('question-board'))question.forEach(q=>{let board_type=q.id.split('-')[0]let question_id=q.id.split('-')[1]let idTag=q.getElementsByClassName('question-id-tag')if(idTag.length===0){idTag=document.createElement('span')idTag.classList.add('question-id-tag')q.children[0].appendChild(idTag)}if(board_type==='question'){idTag.innerHTML=" 題目ID:"+question_id}else if(board_type==='answer'){idTag.innerHTML=" 答案ID:"+question_id}}) } var unblock=()=>{//選擇document.onselectstart= function(e){var e = e || window.event;e.returnValue = true;return true;}//鼠標(biāo)按下document.onmousedown = function(e) {var e = e || window.event;e.returnValue = true;return true;}//鼠標(biāo)右鍵菜單document.oncontextmenu = function(e) {var e = e || window.event;e.returnValue = true;return true;}window.onkeydown = function(e) {//Ctrl+S 保存if (e.ctrlKey && e.keyCode == 83) {e.returnValue = true;return true;}//Ctrl+P 打印if (e.ctrlKey && e.keyCode == 80) {e.returnValue = true;return true;}//Ctrl+C 復(fù)制if (e.ctrlKey && e.keyCode == 67) {e.returnValue = true;return true;}} } //獲取考試信息 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.lengthif(ansNum>0){if(questionNum===examQuestionNum){examUpload()}else{console.log("現(xiàn)在是考試中,不能上傳答案哦。")} }else{answer()appendsomething()unblock() } addIdTag()})();?
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的JavaScript——易班优课YOOC课群在线测试自动答题解决方案(十二)脚本整合的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript——易班优课YOOC
- 下一篇: gradle idea java ssm