From 9cf2f114f9592561aabf4908c6074c4642005e36 Mon Sep 17 00:00:00 2001 From: jinglekang Date: Fri, 5 Jun 2026 17:01:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=E8=87=B32026-06-05.3=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=8F=8C=E5=87=BB=E5=A1=AB=E5=85=A5=E7=AE=80=E7=AD=94?= =?UTF-8?q?=E9=A2=98=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E7=AD=94?= =?UTF-8?q?=E6=A1=88=E5=B1=95=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qingshuxuetang_homework_answer.user.js | 76 ++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 6 deletions(-) diff --git a/qingshuxuetang_homework_answer.user.js b/qingshuxuetang_homework_answer.user.js index d7472d0..81cea61 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.2 +// @version 2026-06-05.3 // @description 在青书学堂作业页面展示官方答案,缺少官方答案时使用 DeepSeek 生成参考答案 // @author JK // @license MIT @@ -142,6 +142,17 @@ margin-bottom: 6px; font-weight: 700; } + + .${ANSWER_CLASS}.fillable { + cursor: pointer; + } + + .${ANSWER_CLASS}.fillable .answer-title::after { + content: "(双击填入)"; + margin-left: 6px; + color: #6b7280; + font-weight: 400; + } `; (document.head || document.documentElement).appendChild(style); }; @@ -376,6 +387,48 @@ return answerDisplay; }; + const findEssayEditor = (questionElement) => + questionElement.querySelector( + ".cke_wysiwyg_div[contenteditable='true'], [contenteditable='true'][role='textbox']" + ); + + const triggerEditorEvents = (editor) => { + ["input", "keyup", "change", "blur"].forEach((eventName) => { + editor.dispatchEvent( + new Event(eventName, { + bubbles: true, + cancelable: true, + }) + ); + }); + }; + + const fillEssayAnswer = (questionElement, answerText) => { + const editor = findEssayEditor(questionElement); + + if (!editor) { + alert("未找到简答题输入框"); + return; + } + + editor.focus(); + editor.innerHTML = ""; + answerText.split(/\n+/).filter(Boolean).forEach((line) => { + const paragraph = document.createElement("p"); + paragraph.textContent = line; + editor.appendChild(paragraph); + }); + triggerEditorEvents(editor); + }; + + const enableEssayFill = (answerDisplay, questionElement, answerText) => { + answerDisplay.classList.add("fillable"); + answerDisplay.title = "双击将答案填入简答题输入框"; + answerDisplay.addEventListener("dblclick", () => { + fillEssayAnswer(questionElement, answerText); + }); + }; + const findQuestionElement = (questionId) => document.querySelector('[id="' + questionId + '"]'); @@ -412,12 +465,19 @@ } if (questionData.solution) { + const officialAnswer = formatOfficialAnswer(questionData); + const answerDisplay = createAnswerDisplay( + "官方答案", + officialAnswer, + "official" + ); + + if (questionData.typeId === 3) { + enableEssayFill(answerDisplay, questionElement, officialAnswer); + } + questionElement.appendChild( - createAnswerDisplay( - "官方答案", - formatOfficialAnswer(questionData), - "official" - ) + answerDisplay ); continue; } @@ -441,6 +501,10 @@ loadingDisplay.querySelector(".answer-title").textContent = "DeepSeek 参考答案"; loadingDisplay.querySelector("div:last-child").textContent = aiAnswer; + + if (questionData.typeId === 3) { + enableEssayFill(loadingDisplay, questionElement, aiAnswer); + } } catch (error) { loadingDisplay.className = ANSWER_CLASS + " error"; loadingDisplay.querySelector(".answer-title").textContent = "获取失败";