Greasy Fork

Greasy Fork is available in English.

深圳大学大物预习题小助手

自动提供参考答案

当前为 2020-12-07 提交的版本,查看 最新版本

// ==UserScript==
// @name         深圳大学大物预习题小助手
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  自动提供参考答案
// @author       nut
// @include      http://172.31.80.15:8101/Student/ReadyForExam/*
// @grant        none
// @require      https://unpkg.com/[email protected]/dist/ajaxhook.min.js
// ==/UserScript==

(function() {
    'use strict';
ah.proxy({onRequest:(config,handler)=>{handler.next(config);},onError:(err,handler)=>{console.log(err.type)
handler.next(err)},onResponse:(response,handler)=>{if(response.config.url=="/Student/ReadyForExam/GetPaperContent"){let finalArr={}
let obj=String(response.response).replace(/\\r\\n/g,"")
let data=JSON.parse(obj).OtherDate
let arrHtml=data.match(/<Question Type=(.*?)<\/Question>/g)
for(const i in arrHtml){let qusArr=arrHtml[i].match(/<Describe>(.*?)<\/Describe>/)[0].match(/Text="(.*?)\"/g)
let quse=""
let ans=arrHtml[i].match(/<StdAnswer>(.*?)<\/StdAnswer>/)[0].slice(11,-12)
for(const j in qusArr){quse+=qusArr[j].replace(/ /g,"").slice(6,-1)}
if(!finalArr[arrHtml[i].slice(16,18)]){finalArr[arrHtml[i].slice(16,18)]=[]}
finalArr[arrHtml[i].slice(16,18)].push({qusetion:quse,answer:ans})}
setTimeout(function(){for(const i in finalArr){let question=document.getElementById(i.toLowerCase())
for(let j=0;j<question.childNodes.length;j=j+2){let item=question.childNodes[j].childNodes[0]
let lastSpan=item.getElementsByTagName("span")[item.getElementsByTagName("span").length-1]
let aSpan=document.createElement("span")
aSpan.style="color: red;font-size: 16px;"
aSpan.innerHTML=finalArr[i][j/2].answer
lastSpan.append(aSpan)}}},2000)}
handler.next(response)}})
})();