新手小白求助,求帮忙分析
新手小白求助,求帮忙分析,求帮忙看一下,这个脚本是跟那个题库对比,看不懂,继续求助// ==UserScript==
// @name 万华学习题库搜索
// @namespace http://server.jcdev.cc:52126/
// @license MIT
// @version 0.1.2
// @description使用档案里的题库,对正在答卷的试题进行匹配,对于匹配到的试题给出正确答案
// @AuThor LFTEC
// @match https://learning.whchem.com:6443/*
// @match https://learning.whchem.com:4443/*
// @Icon https://learning.whchem.com:6443/favicon.ico
// @connect server.jcdev.cc
// @grant GM_xmlhttpRequest
// @grant GM_log
// @grant GM_addElement
// @grant unsafeWindow
// ==/UserScript==
(function() {
'use strict';
function sleep(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve(time);
}, Math.floor(time * 1000))
})
}
function checkElements(){
return new Promise((resolve, reject) => {
let interval = setInterval(() => {
var element = document.getElementsByClassName('answerQuestion');
if(element != undefined) {
let title = document.getElementById("TimerHolder");
if(title == undefined) { return; }
sleep(1).then(() => checkElements())
.then((element) => appendAnswerLink(element));
clearInterval(interval);
resolve(element);
} else {
return;
}
}, 500);
});
}
function appendAnswerLink(element) {
GM_log("检测到正在答题,插入获取答案按钮");
let timerNode = document.getElementById('TimerHolder');
let answerButton = document.getElementById('get_answer');
if(!answerButton) {
answerButton = document.createElement('a');
answerButton.id = 'get_answer';
answerButton.style = 'margin-left: 3em;';
answerButton.innerText = '获取答案';
answerButton.addEventListener('click', () => reportAnswer(element).then());
timerNode.appendChild(answerButton);
GM_log("获取答案按钮正确插入");
}
}
function reportAnswer(element){
return new Promise(resolve => {
GM_log("获取答案中...");
var elements = element.getElementsByClassName('swiper-slide');
elements.forEach(question => {
let questionItem = question.children;
if(questionItem.id.substring(0,12) !== 'questionItem') {return;}
let id = questionItem.id.substring(12);
getAnswer(id).then((data) => fillAnswer(questionItem, data));
});
});
}
function getAnswer(tmid) {
return new Promise(resolve => {
GM_xmlhttpRequest({
method: "GET",
url: "http://server.jcdev.cc:52126/get?id=" + tmid,
responseType: "json",
onload: function(data) {
resolve(data.responseText);
}
});
});
}
function fillAnswer(question, data){
let id = question.id.substring(12);
let trs = question.getElementsByClassName('question-select-item');
if(trs.length === 0) {return;}
let mapping = getAnswerMapping(trs);
let answer = {};
if (data == 'null') {
GM_log("题库中不存在该题目");
answer = {color: '#FF0000', text: '题库中不存在该题目'};
}
else if(data == undefined) {
GM_log("获取题目时发生网络错误");
answer = {color: '#FF0000', text: '获取题目时发生网络错误'};
}
else {
let answers = JSON.parse(data)["Answers"].split(';');
let newAnswers = [];
answers.forEach(answer => {
newAnswers.push(mapping);
});
newAnswers.sort();
GM_log(newAnswers.join(';') + "/" + JSON.parse(data)["Answers"] + "/" + id);
answer = {color: '#018AF4', text: "正确答案:" + newAnswers.join(';')};
}
let answerDiv = question.getElementsByClassName("question-item-right-answer");
InsertAnswerUIElement(answerDiv, answer);
}
function InsertAnswerUIElement(controller, answer) {
let subController = controller.children;
for(let i = subController.length - 1; i >= 0; i--) {
controller.removeChild(subController);
}
let p = document.createElement('p');
p.style.color = answer.color;
p.innerText = answer.text;
controller.appendChild(p);
}
function getAnswerMapping(answers) {
let mapping = {};
answers.forEach(answer => {
let ori = answer.getAttribute('rel_label');
let map = answer.getElementsByClassName('question-select-item-label').innerText;
mapping = map;
});
return mapping;
}
sleep(1).then(() => checkElements())
.then((element) => appendAnswerLink(element));
})(); 从头到尾看一遍代码就很清晰了嘛
function getAnswer(tmid) {
return new Promise(resolve => {
GM_xmlhttpRequest({
method: "GET",
url: "http://server.jcdev.cc:52126/get?id=" + tmid,
responseType: "json",
onload: function(data) {
resolve(data.responseText);
}
});
});
} BurYiA 发表于 2022-7-15 10:13
从头到尾看一遍代码就很清晰了嘛
function getAnswer(tmid) {
我是小白,看不懂能帮忙翻译一下忙
18377194 发表于 2022-7-15 10:15
我是小白,看不懂能帮忙翻译一下忙
啊这,就是这个接口嘛
http://server.jcdev.cc:52126/get?id=
它是利用这个接口来查题返回结果并处理的 BurYiA 发表于 2022-7-15 10:17
啊这,就是这个接口嘛
http://server.jcdev.cc:52126/get?id=
为啥有的题目能自动显示答案,有的显示没有查到,借口不对还是? 18377194 发表于 2022-7-15 10:20
为啥有的题目能自动显示答案,有的显示没有查到,借口不对还是?
需要改一下接口吗? 18377194 发表于 2022-7-15 10:20
为啥有的题目能自动显示答案,有的显示没有查到,借口不对还是?
题库的问题
当搜索的题目在题库中没有记录的时候自然就无法处理咯
换个脚本用呗,之前用过ocs网课助手 还不错,不清楚现在怎么样,可以试试 BurYiA 发表于 2022-7-15 10:23
题库的问题
当搜索的题目在题库中没有记录的时候自然就无法处理咯
这个题库是脚本作者自己建立的,还是服务器上的 18377194 发表于 2022-7-15 10:24
这个题库是脚本作者自己建立的,还是服务器上的
东西肯定是放在服务器上的,题库肯定也是碰不到修改不了的
所以让你换个找的试试嘛,油猴那么多脚本,为啥要死扣一个呢
页:
[1]