diff --git a/script/buct-cource-helper.user.js b/script/buct-cource-helper.user.js index 3e0a78d..fc7709a 100644 --- a/script/buct-cource-helper.user.js +++ b/script/buct-cource-helper.user.js @@ -74,8 +74,18 @@ const question = doc .getElementsByTagName("iframe")[0] .contentDocument.getElementById("body").innerText; - const answer = doc.getElementsByClassName("extable")[0].innerText.replaceAll("\t", "- "); - return question + answer; + const children = getAnswerElement().children[0].children; + const answers = []; + for (const child of children) { + if (child.classList[0] !== "optionContent") { + continue; + } + const labels = child.getElementsByTagName("label"); + for (const label of labels) { + answers.push(label.innerText.trim()); + } + } + return question + answers.map((s) => "- " + s.replaceAll("\t", "")).join("\n"); } function copyToClipboard() { @@ -90,15 +100,29 @@ let answered = false; const answers = answer.split("\n"); const children = getAnswerElement().children[0].children; + const options = {}; for (const child of children) { if (child.classList[0] !== "optionContent") { continue; } - if (answers.includes(child.innerText.replaceAll("\t", ""))) { - child.children[0].children[0].click(); - answered = true; + const labels = child.getElementsByTagName("label"); + if (labels.length > 1) { + for (const label of labels) { + options[label.innerText.trim().replaceAll("\t", "")] = label.children[0]; + } + } else { + options[child.innerText.trim().replaceAll("\t", "")] = + child.children[0].children[0]; } } + for (const answer of answers) { + const input = options[answer.trim()]; + if (!input) { + continue; + } + input.click(); + answered = true; + } if (answered && stat.autoMode) { const done = allDone(); const submitButton = getAnswerElement().nextElementSibling.children[1];