-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
40 lines (36 loc) · 1.27 KB
/
index.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
const { chromium } = require('playwright');
const axios = require('axios');
let answerCount = 1;
(async () => {
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
const usernameDropdownLocator = '#nav-user-dropdown > span';
page.setDefaultTimeout(0);
page.setDefaultNavigationTimeout(0);
// Login
await page.goto('https://www.quill.org/session/new');
console.log('Please signin to continue');
await page.waitForSelector(usernameDropdownLocator);
const name = await page.locator(usernameDropdownLocator).textContent();
console.log(`Login succesful! Welcome, ${name.trim()}!\n`);
// Subscribe to http responses to get question data
page.on('response', (response) => {
if (response.url().includes('responses')) {
axios.get(response.url())
.then((r) => {
// eslint-disable-next-line no-restricted-syntax
for (const answerBlob in r.data) {
// Check if answer is correct
if (r.data[answerBlob].optimal) {
console.log(`Answer ${answerCount}: ${r.data[answerBlob].text}`);
answerCount += 1;
}
}
})
.catch((error) => {
// handle error
console.log(error);
});
}
});
})();