-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (35 loc) · 1.19 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
const puppeteer = require("puppeteer");
const ora = require("ora");
require("dotenv").config();
const spinner = ora("Typerace").start();
const getRandomArbitrary = (min, max) => {
return Math.floor(Math.random() * (max - min) + min);
};
const timeout = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
(async () => {
const browser = await puppeteer.launch({ headless: false, timeout: 30000 });
const page = await browser.newPage();
await page.setViewport({ width: 1200, height: 800 });
await page.goto(process.env.TYPERACE_LINK, {
waitUntil: "networkidle2",
});
await page.waitForSelector(".raceAgainLink", {
visible: true,
});
spinner.text = "Got it";
page.click(".raceAgainLink");
const element = await page.$(".inputPanel tbody tr td div div");
spinner.text = "Copy text";
const content = await element.evaluate((e) => e.textContent);
await page.waitForSelector(".txtInput:not([disabled])", {
visible: true,
});
spinner.text = "Typing...";
const splittedContent = content.split(" ");
for (let word of splittedContent) {
await timeout(getRandomArbitrary(0.4, 1.4) * 1000);
await page.type(".txtInput", word + " ");
}
})();