KeeganT

Join and leave Typeracer races

Jan 15th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Join and leave TypeRacer races
  3. // @namespace   morinted
  4. // @description Join and leave a TypeRacer private racetrack
  5. // @include     https://play.typeracer.com/*
  6. // @version     1
  7. // @grant       none
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
  9. // ==/UserScript==
  10.  
  11.  
  12. var globalCounter = 0
  13. var mainPageCounter = 0
  14. var lastQuoteText = ''
  15.  
  16. function joinOrLeave() {
  17.   var raceAgainLink = (document.getElementsByClassName('raceAgainLink') || [])[0]
  18.   var leaveRaceLink = document.querySelector('table.navControls > tbody > tr > td > a:first-child')
  19.   var gameStatus = ((document.getElementsByClassName('gameStatusLabel') || [])[0] || {}).innerHTML || ''
  20.   if (gameStatus.startsWith('Waiting')) {
  21.     var quoteText = (document.querySelector('table.inputPanel') || {}).textContent || ''
  22.     if (quoteText && quoteText !== lastQuoteText) {
  23.       lastQuoteText = quoteText
  24.       var chatInput = $('input.txtChatMsgInput')
  25.       chatInput.click()
  26.       chatInput.val(' >> ' + quoteText)
  27.       chatInput.focus()
  28.       var keyboardEvent = jQuery.Event('keydown')
  29.       keyboardEvent.which = 13
  30.       keyboardEvent.keyCode = 13
  31.       chatInput.trigger(keyboardEvent)
  32.  
  33.     }
  34.   } else if (gameStatus.startsWith('The race is about to start')) {
  35.     // Nothing
  36.   } else if (gameStatus.startsWith('Join')) {
  37.     raceAgainLink.click()
  38.     setTimeout(joinOrLeave, 200)
  39.     globalCounter = 0
  40.   } else if (gameStatus.startsWith('Go!') || gameStatus.startsWith('The race is on!')) {
  41.     leaveRaceLink.click()
  42.     globalCounter = 0
  43.   } else if (gameStatus.startsWith('The race has ended')) {
  44.     document.body.click()
  45.     // Do nothing.
  46.   } else {
  47.     if (document.querySelector('.mainMenuItemText')) {
  48.       mainPageCounter += 1
  49.     }
  50.     // Maybe kicked out?
  51.     $('.lnkRejoin').click() // Rejoin
  52.     // Race your friends link
  53.     $('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()
  54.     if (mainPageCounter > 1) {
  55.       location.reload()
  56.       mainPageCounter = 0
  57.     }
  58.   }
  59. }
  60.  
  61. function loopJoinOrLeave() {
  62.   setTimeout(function() {
  63.     joinOrLeave()
  64.     loopJoinOrLeave()
  65.   }, 1000)
  66. }
  67. loopJoinOrLeave()
Advertisement
Add Comment
Please, Sign In to add comment