Skip to content

Instantly share code, notes, and snippets.

@morinted
Created June 4, 2017 02:45
Show Gist options
  • Save morinted/ad14f5bc64c80e21ee5cb36fa69b2439 to your computer and use it in GitHub Desktop.
Save morinted/ad14f5bc64c80e21ee5cb36fa69b2439 to your computer and use it in GitHub Desktop.
TypeRacer auto-join private track bot
// ==UserScript==
// @name Join and leave TypeRacer races
// @namespace morinted
// @description Join and leave a TypeRacer private racetrack
// @include http://play.typeracer.com/
// @version 1
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// ==/UserScript==
var globalCounter = 0
var mainPageCounter = 0
var lastQuoteText = ''
function joinOrLeave() {
var raceAgainLink = (document.getElementsByClassName('raceAgainLink') || [])[0]
var leaveRaceLink = document.querySelector('table.navControls > tbody > tr > td > a:first-child')
var gameStatus = ((document.getElementsByClassName('gameStatusLabel') || [])[0] || {}).innerHTML || ''
if (gameStatus.startsWith('Waiting')) {
var quoteText = (document.querySelector('table.inputPanel') || {}).textContent || ''
if (quoteText && quoteText !== lastQuoteText) {
lastQuoteText = quoteText
var chatInput = $('input.txtChatMsgInput')
chatInput.click()
chatInput.val(' >> ' + quoteText)
chatInput.focus()
var keyboardEvent = jQuery.Event('keydown')
keyboardEvent.which = 13
keyboardEvent.keyCode = 13
chatInput.trigger(keyboardEvent)
}
} else if (gameStatus.startsWith('The race is about to start')) {
// Nothing
} else if (gameStatus.startsWith('Join')) {
raceAgainLink.click()
setTimeout(joinOrLeave, 200)
globalCounter = 0
} else if (gameStatus.startsWith('Go!') || gameStatus.startsWith('The race is on!')) {
leaveRaceLink.click()
globalCounter = 0
} else if (gameStatus.startsWith('The race has ended')) {
document.body.click()
// Do nothing.
} else {
if (document.querySelector('.mainMenuItemText')) {
mainPageCounter += 1
}
// Maybe kicked out?
$('.lnkRejoin').click() // Rejoin
// Race your friends link
$('div.mainViewport > div > table > tbody > tr:nth-child(4) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(1) > td > a').click()
if (mainPageCounter > 1) {
location.reload()
mainPageCounter = 0
}
}
}
function loopJoinOrLeave() {
setTimeout(function() {
joinOrLeave()
loopJoinOrLeave()
}, 1000)
}
loopJoinOrLeave()
Copy link

ghost commented Aug 19, 2018

<3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment