-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
79 lines (60 loc) · 1.78 KB
/
bot.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
const puppeteer = require('puppeteer');
const { URL } = require('url');
const { loginToTFF, sleep } = require('./utils');
/*
** change here the speed, corresponding to sleep time between words (lower is faster), delay betweend each type, pause behavior, and location
*/
const config = {
speed: 150,
delay: 0,
shouldPause: true,
pauseAfter: 150,
pauseFor: 10000,
location: "https://10fastfingers.com/typing-test/french"
}
const wordsEvaluate = () => Array.from(
document.querySelectorAll("span[wordnr]")
).map(word => word.innerText)
const fillInWords = async (
puppeteerPage,
url
) => {
await puppeteerPage.goto(url);
await puppeteerPage.waitForSelector("span.highlight");
// gets the whole word list on a single move
const wordList = await puppeteerPage.evaluate(wordsEvaluate);
// here comes the magic
puppeteerPage.click("input#inputfield.form-control");
let i = 0;
for (const word of wordList) {
if (config.shouldPause) {
i++;
if (i === config.pauseAfter) {
sleep(config.pauseFor);
}
}
await puppeteerPage.keyboard.type(word + ' ', {delay: config.delay});
sleep(config.speed);
}
}
const run = async () => {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: {
width: 1000,
height: 3000,
}
});
if (process.argv[2] && process.argv[3]) {
const mail = process.argv[2];
const pass = process.argv[3];
await loginToTFF(browser, mail, pass);
}
/*
** change URL to change language
*/
const location = new URL(config.location);
const page = await browser.newPage();
await fillInWords(page, location);
}
run();