-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
41 lines (40 loc) · 1.53 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(async function () {
chrome.storage.local.get("jsonData", function (data) {
if (data.jsonData) {
const questions = document.querySelectorAll(
'div[data-automation-id="questionItem"]'
);
questions.forEach((execute) => {
const questionText = formatText(
execute.querySelector("span.text-format-content")
.textContent
).trim(),
ans = data.jsonData.find(
(item) => formatText(item.question) === questionText
)?.answer;
if (ans) {
execute
.querySelectorAll(
'div[data-automation-id="choiceItem"]'
)
.forEach((choice) => {
const choiceText = choice
.querySelector("span.text-format-content")
.textContent.trim();
if (ans.includes(formatText(choiceText))) {
choice.querySelector("label").click();
}
});
}
});
} else {
console.log("No JSON data found. Please upload a JSON file.");
}
});
})();
const formatText = (text) =>
text
.replace(/\s+/g, " ")
.replace(/“|”/g, '"')
.replace(/–/g, "-")
.normalize("NFC");