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