更新脚本版本号至2026-06-05.3,新增双击填入简答题功能,优化答案展示逻辑
This commit is contained in:
parent
91a2032c87
commit
9cf2f114f9
|
|
@ -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) {
|
||||
questionElement.appendChild(
|
||||
createAnswerDisplay(
|
||||
const officialAnswer = formatOfficialAnswer(questionData);
|
||||
const answerDisplay = createAnswerDisplay(
|
||||
"官方答案",
|
||||
formatOfficialAnswer(questionData),
|
||||
officialAnswer,
|
||||
"official"
|
||||
)
|
||||
);
|
||||
|
||||
if (questionData.typeId === 3) {
|
||||
enableEssayFill(answerDisplay, questionElement, officialAnswer);
|
||||
}
|
||||
|
||||
questionElement.appendChild(
|
||||
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 = "获取失败";
|
||||
|
|
|
|||
Loading…
Reference in New Issue