-
Notifications
You must be signed in to change notification settings - Fork 0
/
question.js
79 lines (64 loc) · 2.13 KB
/
question.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* eslint-disable no-undef */
const axios = require("axios");
const solve = require("./validate.js");
const API = "https://us-central1-p3a-dayquestion.cloudfunctions.net/g";
async function question(page, token) {
try {
await solve(page, token);
const obj = {};
const question = await page.evaluate(() => {
const questionNode = document.querySelector(
"#fwin_pop font[color='#FF6600']"
).lastChild;
return questionNode.textContent.trim();
});
const options = await page.evaluate(() => {
// const optionNodes = document.querySelectorAll(".qs_option");
// return Array.from(optionNodes).map(node => node.textContent.trim());
let opts = [];
for (let i = 1; i <= 4; i++) {
const selector = `div[onclick="document.getElementById('a${i}').checked='checked';"]`;
const element = document.querySelector(selector);
if (element) {
opts.push(element.innerText.trim());
}
}
return opts;
});
obj["q"] = question;
obj["o"] = options;
var data = JSON.stringify({
data: obj,
});
var config = {
method: "post",
url: API,
headers: {
"content-type": "application/json",
},
data: data,
};
const response = await axios(config);
const res = response.data;
let ansIdx;
for (let i in res["result"]) {
if (res["result"][i]) ansIdx = Number(i) + 1;
}
await page.click(
`div[onclick="document.getElementById('a${ansIdx}').checked='checked';"]`
);
await Promise.all([
page.click(".pnc"),
page.waitForNavigation({ waitUntil: "networkidle2" }),
]);
await new Promise((resolve) =>
setTimeout(function () {
resolve();
}, 3000)
);
} catch (err) {
console.trace(err);
throw err;
}
}
module.exports = question;