-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (27 loc) · 949 Bytes
/
app.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
const puppeteer = require('puppeteer');
function delay(timeout) {
return new Promise((resolve) => {
setTimeout(resolve, timeout);
});
}
const Play = async (page) => {
await delay(1000);
await page.$$eval("a", as => as.find(a => a.innerText.includes("Enter a typing race")).click());
await delay(2000);
const data = await page.evaluate(() => {
const tds = Array.from(document.querySelectorAll('table tbody tr td div div span[unselectable]'))
return tds.map(span => span.textContent)
});
await delay(12500);
const textField = await page.$('input[class=txtInput]');
await textField.type(data.join(""),{ delay: 20 });
await textField.dispose();
}
async function run() {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.setViewport({width: 1200, height: 900});
await page.goto('http://play.typeracer.com/');
await Play(page);
}
run();