Created
June 4, 2017 02:45
-
-
Save morinted/ad14f5bc64c80e21ee5cb36fa69b2439 to your computer and use it in GitHub Desktop.
TypeRacer auto-join private track bot
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
// ==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
<3