Skip to content

Commit 321aaf1

Browse files
committed
fix: resolve incorrect element selectors in assessment content script
1 parent 10d6c58 commit 321aaf1

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

entrypoints/assessment.content.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,24 @@ export default defineContentScript({
9999
(ele as HTMLTextAreaElement).value = ConsSentences.pickRandom()
100100
}
101101
}
102-
// 其他
103-
([...document.querySelectorAll(`tr:not([bgcolor="#CCFFCC"])>td:nth-child(2)>input[type="checkbox"]`)].at(-1) as HTMLInputElement).checked = false
102+
// 避免勾選到「其他」,因為選了就需要填寫文字原因
103+
document.querySelectorAll('input[type="checkbox"], input[type="radio"]').forEach(ele => {
104+
if (ele.nextSibling && ele.nextSibling.nodeType === 3 && ele.nextSibling.textContent?.includes('其他')) {
105+
(ele as HTMLInputElement).checked = false;
106+
}
107+
});
104108

105109
// 特殊題型 (colspan="5"):不管同意或不同意,一律勾選「是」
106110
document.querySelectorAll('td[colspan] input[type="radio"][value="A"]').forEach(ele => (ele as HTMLInputElement).checked = true);
107111
document.querySelectorAll('td[colspan] input[type="checkbox"][value="A"]').forEach(ele => (ele as HTMLInputElement).checked = true);
108112

113+
// 如果還有沒填寫到的文字輸入框 (input[type="text"]),自動填入預設回覆
114+
document.querySelectorAll('input[type="text"]').forEach(ele => {
115+
if (!(ele as HTMLInputElement).value) {
116+
(ele as HTMLInputElement).value = "我其實沒什麼想法:)";
117+
}
118+
});
119+
109120
// @ts-ignore
110121
Swal.fire('填寫完畢', '記得檢查一下內容再送出', 'success')
111122
}

0 commit comments

Comments
 (0)