更新脚本版本号至2026-06-05.2,新增答案格式化功能,优化答案展示逻辑
This commit is contained in:
parent
590229275c
commit
91a2032c87
|
|
@ -1,7 +1,7 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name 平顶山学院(青书学堂)作业答案助手
|
// @name 平顶山学院(青书学堂)作业答案助手
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 2026-06-05.1
|
// @version 2026-06-05.2
|
||||||
// @description 在青书学堂作业页面展示官方答案,缺少官方答案时使用 DeepSeek 生成参考答案
|
// @description 在青书学堂作业页面展示官方答案,缺少官方答案时使用 DeepSeek 生成参考答案
|
||||||
// @author JK
|
// @author JK
|
||||||
// @license MIT
|
// @license MIT
|
||||||
|
|
@ -232,6 +232,44 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const htmlToText = (html = "") => {
|
||||||
|
const element = document.createElement("div");
|
||||||
|
element.innerHTML = html;
|
||||||
|
|
||||||
|
return element.textContent.trim();
|
||||||
|
};
|
||||||
|
|
||||||
|
const parseAnswerLabels = (solution = "") => {
|
||||||
|
const text = htmlToText(solution).toUpperCase();
|
||||||
|
const labels = text.match(/[A-Z]/g) || [];
|
||||||
|
|
||||||
|
return Array.from(new Set(labels));
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatOfficialAnswer = (questionData) => {
|
||||||
|
const solution = questionData.solution || "";
|
||||||
|
const answerLabels = parseAnswerLabels(solution);
|
||||||
|
|
||||||
|
if (answerLabels.length === 0 || !questionData.options?.length) {
|
||||||
|
return htmlToText(solution) || solution;
|
||||||
|
}
|
||||||
|
|
||||||
|
const optionMap = new Map(
|
||||||
|
questionData.options.map((option) => [
|
||||||
|
String(option.label || "").trim().toUpperCase(),
|
||||||
|
htmlToText(option.description),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
const matchedAnswers = answerLabels.map((label) => {
|
||||||
|
const optionText = optionMap.get(label);
|
||||||
|
|
||||||
|
return optionText ? label + ". " + optionText : label;
|
||||||
|
});
|
||||||
|
|
||||||
|
return matchedAnswers.join("\n");
|
||||||
|
};
|
||||||
|
|
||||||
const getQuestionTypeName = (typeId) => {
|
const getQuestionTypeName = (typeId) => {
|
||||||
if (typeId === 1) {
|
if (typeId === 1) {
|
||||||
return "单选题";
|
return "单选题";
|
||||||
|
|
@ -375,7 +413,11 @@
|
||||||
|
|
||||||
if (questionData.solution) {
|
if (questionData.solution) {
|
||||||
questionElement.appendChild(
|
questionElement.appendChild(
|
||||||
createAnswerDisplay("官方答案", questionData.solution, "official")
|
createAnswerDisplay(
|
||||||
|
"官方答案",
|
||||||
|
formatOfficialAnswer(questionData),
|
||||||
|
"official"
|
||||||
|
)
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue