更新脚本版本号至2026-06-05.10,新增对简答题类型的支持,优化答案填充逻辑

This commit is contained in:
竟康 2026-06-05 17:26:57 +08:00
parent db94f21953
commit 26d41ae4d8
1 changed files with 22 additions and 7 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name 平顶山学院(青书学堂)作业答案助手 // @name 平顶山学院(青书学堂)作业答案助手
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 2026-06-05.4 // @version 2026-06-05.10
// @description 在青书学堂作业页面展示官方答案,缺少官方答案时使用 DeepSeek 生成参考答案 // @description 在青书学堂作业页面展示官方答案,缺少官方答案时使用 DeepSeek 生成参考答案
// @author JK // @author JK
// @license MIT // @license MIT
@ -22,6 +22,8 @@
const CONFIG_STORAGE_KEY = "qingshu_homework_answer_config"; const CONFIG_STORAGE_KEY = "qingshu_homework_answer_config";
const ANSWER_CLASS = "qingshu-homework-answer"; const ANSWER_CLASS = "qingshu-homework-answer";
const STYLE_ID = "qingshu-homework-answer-style"; const STYLE_ID = "qingshu-homework-answer-style";
const ESSAY_EDITOR_SELECTOR =
".cke_wysiwyg_div[contenteditable='true'], [contenteditable='true'][role='textbox']";
const DEFAULT_CONFIG = { const DEFAULT_CONFIG = {
deepseekApiKey: "", deepseekApiKey: "",
@ -290,7 +292,7 @@
return "多选题"; return "多选题";
} }
if (typeId === 3) { if (typeId === 3 || typeId === 8) {
return "简答题"; return "简答题";
} }
@ -387,10 +389,14 @@
return answerDisplay; return answerDisplay;
}; };
const findQuestionContainer = (questionElement) =>
questionElement.closest(".question-detail-container") || questionElement;
const findEssayEditor = (questionElement) => const findEssayEditor = (questionElement) =>
questionElement.querySelector( findQuestionContainer(questionElement).querySelector(ESSAY_EDITOR_SELECTOR);
".cke_wysiwyg_div[contenteditable='true'], [contenteditable='true'][role='textbox']"
); const isEssayQuestion = (questionData) =>
questionData.typeId === 3 || questionData.typeId === 8;
const triggerEditorEvents = (editor) => { const triggerEditorEvents = (editor) => {
["input", "keyup", "change", "blur"].forEach((eventName) => { ["input", "keyup", "change", "blur"].forEach((eventName) => {
@ -464,6 +470,15 @@
continue; continue;
} }
console.log("青书作业题目识别:", {
questionId: questionData.questionId,
typeId: questionData.typeId,
typeName: getQuestionTypeName(questionData.typeId),
hasEssayEditor: Boolean(findEssayEditor(questionElement)),
hasOfficialAnswer: Boolean(questionData.solution),
hasUserAnswer: Boolean(questionData.userAnswer),
});
if (questionData.solution) { if (questionData.solution) {
const officialAnswer = formatOfficialAnswer(questionData); const officialAnswer = formatOfficialAnswer(questionData);
const answerDisplay = createAnswerDisplay( const answerDisplay = createAnswerDisplay(
@ -472,7 +487,7 @@
"official" "official"
); );
if (questionData.typeId === 3) { if (isEssayQuestion(questionData)) {
enableEssayFill(answerDisplay, questionElement, officialAnswer); enableEssayFill(answerDisplay, questionElement, officialAnswer);
} }
@ -502,7 +517,7 @@
"DeepSeek 参考答案"; "DeepSeek 参考答案";
loadingDisplay.querySelector("div:last-child").textContent = aiAnswer; loadingDisplay.querySelector("div:last-child").textContent = aiAnswer;
if (questionData.typeId === 3) { if (isEssayQuestion(questionData)) {
enableEssayFill(loadingDisplay, questionElement, aiAnswer); enableEssayFill(loadingDisplay, questionElement, aiAnswer);
} }
} catch (error) { } catch (error) {