-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
123 lines (95 loc) · 3.42 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const puppeteer = require('puppeteer');
//please create user's own config file {user:'', pass:''} and import here
const config = require('./config.js')
const readline = require('readline-promise');
const {
getCollection,
initDB,
getDB
} = require('lokijs-promise')
// await initDB('english.json', 1000)
const rlp = readline.default.createInterface({
input: process.stdin,
output: process.stdout,
terminal: true
});
puppeteer.launch({
headless: false
}).then(async browser => {
const page = await browser.newPage();
await page.goto('https://web.shanbay.com/web/account/login/');
console.log('connected.')
await page.waitForSelector('#input-account')
await page.type('#input-account', config.user, {
// delay: 100
});
await page.waitForSelector('#input-password')
await page.type('#input-password', config.pass, {
// delay: 100
});
await page.waitForSelector('#button-login')
await page.click('#button-login')
await page.waitForNavigation()
let keepChecking = true;
while (keepChecking) {
await page.goto('https://www.shanbay.com/bdc/spotcheck/');
await page.waitForSelector('#spotcheck-test > ul')
let words = await page.$$('#spotcheck-test > ul > li')
let currentCount = 0;
while (true) {
if (currentCount < 0) {
currentCount = 0;
}
let wordEl = words[currentCount];
let wordText = await wordEl.$eval('label', node => node.innerText)
let checked = await wordEl.$eval('label > input', c => c.checked)
//make the font of checking words green.
console.log('\x1b[32m%s\x1b[0m', `${wordText.trim()}`);
let answer = await rlp.questionAsync(`Remember? [y]es or (n)o or (d)ictionary or (p)revious : `)
if (answer.trim() === 'n') {
if (!checked) {
await wordEl.click();
}
} else if (answer.trim() === 'd') {
console.log('webster maybe.')
continue;
} else if (answer.trim() === 'p') {
currentCount -= 1;
continue;
}
currentCount++;
if (currentCount >= words.length) {
let answer = await rlp.questionAsync(`One set more? (y)es or [n]o or (p)revious : `);
if (answer.trim() === 'y') {
break;
} else if (answer.trim() === 'p') {
currentCount -= 1;
continue;
}
keepChecking = false;
break;
}
}
//submit and save word list
let remembered = [];
let forgotten = [];
for (n in words) {
let wordEl = words[n];
let wordText = await wordEl.$eval('label', node => node.innerText)
let checked = await wordEl.$eval('label > input', c => c.checked)
if (checked) {
forgotten.push(wordText.trim());
} else {
remembered.push(wordText.trim());
}
}
//save word list
//submit
if (forgotten.length != 0) {
await page.waitForSelector('#submit-spotcheck');
await page.click('#submit-spotcheck');
await page.waitForNavigation()
}
}
// await browser.close();
});