From 44218408b085f57cbf85cc67e977492ac8519bac Mon Sep 17 00:00:00 2001 From: Bluemangoo Date: Wed, 1 Apr 2026 16:37:31 +0800 Subject: [PATCH] fix strip --- script/buct-cource-helper.user.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/script/buct-cource-helper.user.js b/script/buct-cource-helper.user.js index 415cfec..c873396 100644 --- a/script/buct-cource-helper.user.js +++ b/script/buct-cource-helper.user.js @@ -23,6 +23,10 @@ autoMode: false }; + function strip(s) { + return s.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); + } + class Poll { polling = true; @@ -82,9 +86,10 @@ } const labels = child.getElementsByTagName("label"); for (const label of labels) { - answers.push(label.innerText.trim()); + answers.push(strip(label.innerText)); } } + console.log(answers); return question + "\n\n" + answers.map((s) => "- " + s.replaceAll("\t", "")).join("\n"); } @@ -108,15 +113,15 @@ const labels = child.getElementsByTagName("label"); if (labels.length > 1) { for (const label of labels) { - options[label.innerText.trim().replaceAll("\t", "")] = label.children[0]; + options[strip(label.innerText)] = label.children[0]; } } else { - options[child.innerText.trim().replaceAll("\t", "")] = + options[strip(child.innerText)] = child.children[0].children[0]; } } for (const answer of answers) { - const input = options[answer.trim()]; + const input = options[strip(answer)]; if (!input) { continue; }