Created
January 18, 2020 04:29
-
-
Save jjason685/79afc7b3cecd9f79703586962407914c to your computer and use it in GitHub Desktop.
TypeRacer Hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer'); | |
function delay(timeout) { | |
return new Promise((resolve) => { | |
setTimeout(resolve, timeout); | |
}); | |
} | |
const play = async (page) => { | |
await page.waitForSelector('table tbody tr td div div span[unselectable]'); | |
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 page.waitForSelector('.txtInput') | |
const textField = await page.$('.txtInput'); | |
let status = await page.$('.gameStatusLabel'); | |
let text = await page.evaluate(status => status.textContent, status); | |
while (text !== 'The race is on! Type the text below:') { | |
status = await page.$('.gameStatusLabel'); | |
text = await page.evaluate(status => status.textContent, status); | |
await delay(75); | |
} | |
for (let word of data) { | |
await textField.type(word, { delay: Math.floor(Math.random() * 9) + 9 }); | |
} | |
await textField.dispose(); | |
} | |
async function run() { | |
const browser = await puppeteer.launch({ headless: true }); | |
const page = await browser.newPage(); | |
await page.setViewport({ width: 1200, height: 900 }); | |
await page.goto('https://play.typeracer.com?rt=xeci0ulhy'); | |
await page.waitForSelector('.raceAgainLink'); | |
await page.click('.raceAgainLink'); | |
await play(page); | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(its a joke i love you jason)