'
});
}
let isShow = true
var showanswer = ()=>{
if (isShow){
let url = location.href
let arr = url.split("/")
let book = arr[arr.length-7]
let unit = arr[arr.length-2]
let answer = []
GM_xmlhttpRequest({
method: 'GET',
url: 'https://ucontentapi.unipus.cn/course/api/content/'+book+'/'+unit+'/default/',
headers: {
'X-ANNOTATOR-AUTH-TOKEN': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvcGVuX2lkIjoidHV4NkNCQVc4aGRrcnFZdzc5SEpEWDF2aTR5Z2ptcDUiLCJuYW1lIjoiIiwiZW1haWwiOiIiLCJhZG1pbmlzdHJhdG9yIjoiZmFsc2UiLCJleHAiOjE5MDI5NzAxNTcwMDAsImlzcyI6IlI0aG03RmxQOFdvS0xaMUNmTkllIiwiYXVkIjoiZWR4LnVuaXB1cy5jbiJ9.CwuQmnSmIuts3hHAMf9lT954rKHXUNkps-PfRJp0KnU'
},
timeout: 5000,
onload: function(xhr) {
if (xhr.status == 200) {
let el = '
' + '
'
console.log('https://ucontentapi.unipus.cn/course/api/content/'+book+'/'+unit+'/default/')
console.log(xhr.responseText)
let obj = JSON.parse(xhr.responseText) || {};
let deObj = decryptContent(obj);
let keyList = Object.keys(deObj);
console.log(keyList)
Array.prototype.contains = function (obj) {
var index = this.length;
while (index--) {
if (this[index] === obj) {
return true;
}
}
return false;
}
// 选择题
if (keyList.contains('questions:questions')) {
let questionList = deObj['questions:questions'].questions;
let lineCount = 0; // 初始化行数计数器
for (let question of questionList) {
let result = '';
if (question.answers) {
result += question.answers.join(' ');
}
// 在每一行前加上行号
lineCount++; // 增加行数
el = el + '
';
}
// 简答题
if (keyList.contains('shortanswer:shortanswer')) {
let questionList = deObj['shortanswer:shortanswer'].questions;
let lineCount = 0; // 初始化行数计数器
for (let question of questionList) {
lineCount++; // 每处理一个题目,行数加 1
el = el + '
';
}
// 填空题
if (keyList.contains('questions:scoopquestions')) {
let questionList = deObj['questions:scoopquestions'].questions;
let lineCount = 0; // 初始化行数计数器
for (let question of questionList) {
lineCount++; // 每处理一个题目,行数加 1
let result = '';
if (question.answers) {
result += question.answers.join(' ');
}
// 输出包含行号的 HTML
el = el + '
';
console.log(el); // 打印当前的 HTML 内容到控制台
}
// 可选:在最后添加总行数统计
el = el + '
总题数: ' + lineCount + '
';
}
// 短回答题
if (keyList.contains('questions:shortanswer')) {
let questionList = deObj['questions:shortanswer'].questions;
let lineCount = 0; // 初始化行数计数器
for (let question of questionList) {
lineCount++; // 每处理一个题目,行数加 1
let result = '';
if (question.answers) {
result += question.answers.join(' ');
}
// 输出包含行号的 HTML
el = el + '