-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
41 lines (39 loc) · 1.93 KB
/
main.js
File metadata and controls
41 lines (39 loc) · 1.93 KB
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
const sleep = async ms => new Promise(res => setTimeout(() => res(), ms));
setInterval(async () => {
const iframe = document.getElementById('contentFrame');
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (iframeDocument.querySelector('div[data-controltype="submitinfo"]')?.textContent == '尚未提交。') {
iframeDocument.querySelectorAll('li[data-choiced]:not([data-solution])').forEach(el => el.click());
iframeDocument.querySelectorAll('li[data-solution]:not([data-choiced])').forEach(el => el.click());
const results = iframeDocument.querySelectorAll('div[data-itemtype="result"]');
results.forEach(result => {
const solution = result.textContent;
const answer = solution.split("/")[0].replace('(Answers may vary.)', '').replace(/[ \n]+/g, ' ').trim();
const input = result.closest('div').parentElement.querySelector('input[data-itemtype="input"]');
if (input) {
input.value = answer;
}
const myResult = result.closest('div').parentElement.querySelector('div[data-itemtype="myresult"]');
if (myResult) {
myResult.innerHTML = answer;
}
const choiceList = result.closest('div[data-controltype="choice"]');
if (choiceList) {
const optionItems = choiceList.querySelectorAll('li[data-solution=""]');
optionItems.forEach(option => {
option.setAttribute('data-choiced', '');
});
}
const textarea = result.closest('div').parentElement.querySelector('textarea[data-itemtype="textarea"]');
if (textarea) {
textarea.value = answer;
}
});
await sleep(250);
iframeDocument.querySelector('a[data-controltype="submit"]').click();
await sleep(250);
iframeDocument.querySelector('a.layui-layer-btn0').click();
}
await sleep(250);
iframeDocument.querySelector('div.nextcmd').click();
}, 1000); // 1000 可改大,尽量不要改小,最好不要小于 800