Skip to content

Instantly share code, notes, and snippets.

@mmikeww
Forked from morinted/join-races.js
Created June 10, 2017 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmikeww/70afe2974ec5c78197589fe4a361265a to your computer and use it in GitHub Desktop.
Save mmikeww/70afe2974ec5c78197589fe4a361265a 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment