Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Join and leave TypeRacer races
- // @namespace morinted
- // @description Join and leave a TypeRacer private racetrack
- // @include https://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()
Advertisement
Add Comment
Please, Sign In to add comment