Created
November 15, 2021 16:59
-
-
Save thomas-catt/569a0be22bb32e31c791c588b53864cb to your computer and use it in GitHub Desktop.
play.typeracer.com Auto-typing 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
/* _____________________________________ | |
/ \ | |
| TYPERACER AUTOMATION CODE | | |
| by thomascatt :) | | |
\_____________________________________/ | |
HOW TO USE: | |
- paste all below code in console | |
(if you run into problems, read the Gotchas section below) | |
WHAT DOES IT DO: | |
- heck button: types in the displayed paragraph at a specified wpm speed | |
- automate button: endlessly automates typing once the Automate racing button is pressed | |
- the automate ode | |
- the automation will exit if it encounters an anti-cheat challange | |
GOTCHAS: DO-S AND DON'T-S: | |
- IMPORTANT: Press the Automate button BEFORE pressing anything else: the automation code automates the start button too | |
- Avoid pressing the Heck button while the automation is in process | |
- Keep the window focused to achieve the specified WPM more accurately | |
- you can set the speed variable (just speed) to some value for the automation to pick up. note that this value will not affect the current running race instance. | |
Default is 125. this speed is the number of milliseconds of delay in every keystroke automated. (Lower values trigger the anti-cheat, remember that) | |
*/ | |
var startHTML = "<a onclick='automate()' id='automate-btn' class='gwt-Anchor prompt-button bkgnd-orange'>Automate racing</a></div>" | |
document.querySelector(".title").innerHTML += "<div style=\"display: flex; justify-content: center; align-items: center; font-size: 16px;\"><a onclick='customheck(parseInt(prompt(\"Enter keystroke hit rate (delay between each key press) (value below 120 might trigger an anti-cheat challange)\n\nIf you didnt understand anything then just put in 150 below\")))' class='gwt-Anchor prompt-button bkgnd-green'>Heck (with speed)</a>"+startHTML | |
window.heck = function() {document.querySelector("input.txtInput").value = document.querySelector("table.inputPanel div").innerText } | |
window.keyEvent = function(element) { | |
element = element || document | |
var keyboardEvent = document.createEvent('KeyboardEvent'); | |
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? 'initKeyboardEvent' : 'initKeyEvent'; | |
keyboardEvent[initMethod]( | |
'keydown', // event type: keydown, keyup, keypress | |
true, // bubbles | |
true, // cancelable | |
window, // view: should be window | |
false, // ctrlKey | |
false, // altKey | |
false, // shiftKey | |
false, // metaKey | |
40, // keyCode: unsigned long - the virtual key code, else 0 | |
0, // charCode: unsigned long - the Unicode character associated with the depressed key, else 0 | |
); | |
element.dispatchEvent(keyboardEvent); | |
} | |
window.customheck = function(speed, callback) { | |
try{ | |
if (isNaN(speed)) return | |
var i = 0; | |
var text = document.querySelector("table.inputPanel div").innerText.substr() | |
if (window['hecking'] !== undefined) clearInterval(window.hecking) | |
window.hecking = setInterval(function() { | |
if (document.querySelector("input.txtInput") == undefined || document.querySelector("table.inputPanel div") == undefined) throw "An error occured" | |
document.querySelector("input.txtInput").value += text.substr(i, 1) | |
if ( (text.length <= i) && (callback !== undefined)) { callback(); clearInterval(window.hecking) } | |
i++; | |
keyEvent(document.querySelector("input.txtInput")) | |
}, speed) | |
} catch(e) { | |
clearInterval(window.hecking) | |
alert("Typing cancelled due to error.") | |
console.group("Typing cancelled due to error.") | |
console.log(e) | |
console.groupEnd("Typing cancelled due to error.") | |
} | |
} | |
window.automate = function() { | |
var automationLogMessage = function(m) { | |
document.querySelector('#automate-log').innerHTML = m | |
console.log(m) | |
} | |
try { | |
var startedTx = "<span id='automate-btn' style='font-size: 24px;'>Automation Started</span>" | |
var el = document.querySelector("#automate-btn") | |
if (el.innerHTML == startedTx) return; | |
el.outerHTML = "<center style='display: block; width: 15vw;'" + startedTx + " <div id='automate-log' style='color: green;'></div></center>" | |
automationLogMessage("Attempting to endlessly automate racing. Try not to interfere with the UI while in progress.") | |
// click button | |
var waitLoad = setInterval(function () { | |
if (document.querySelector('#gwt-uid-1 a') == null) return | |
document.querySelector('#gwt-uid-1 a').click() | |
automationLogMessage("Waiting to find match...") | |
clearInterval(waitLoad) | |
}, 100) | |
var findMatch = setInterval(function() { | |
if (document.querySelector('#gwt-uid-1 a') == undefined) { | |
// match found | |
getReady() | |
clearInterval(findMatch) | |
} | |
}, 500) | |
function getReady() { | |
automationLogMessage("Found match, counting down...") | |
var readyMatch = setInterval(function() { | |
if (document.querySelector('.countdownPopup .lightLabel') && document.querySelector('.countdownPopup .lightLabel').innerText.includes("Go")) { | |
// match started | |
var typingspeed = window.speed || 125 | |
var typingspeedWpm = Math.round(typingspeed*0.72) | |
automationLogMessage("Match started, typing triggered @ "+typingspeedWpm+"keystrokes/ms. " + ( (typingspeedWpm < 90) ? "<span style='color: orange'><b>High wpm </b>- Might cause a challange to appear</span>" : "" ) ) | |
customheck(typingspeed, function() { | |
automationLogMessage("Typing Finished.") | |
var waitForRetry = setInterval( function () { | |
if (document.querySelector('.challengePromptDialog') != null || document.querySelector(".raceAgainLink") == null) { | |
var msg = ( (document.querySelector(".raceAgainLink") == null) ? "Disqualified from match, reloading..." : "Challange appeared, reloading...") | |
automationLogMessage(msg) | |
document.querySelector("#automate-btn").outerHTML = startHTML | |
if (confirm(msg+"\n\nPress OK to reload, cancel to stop automation")) location.reload() | |
automationLogMessage('') | |
clearInterval(waitForRetry) | |
clearInterval(hecking) | |
} | |
if (document.querySelector(".raceAgainLink").style.display == "none") return; | |
var wpm = parseInt(document.querySelector('.rankPanelWpm-self').innerText.replace('wpm', '')) | |
automationLogMessage("\nRace Finished, WPM achieved: "+wpm+" wpm\nStarting again... ") | |
clearInterval(waitForRetry) | |
setTimeout(function () { | |
document.querySelector(".raceAgainLink").click() | |
getReady() | |
}, 1000) | |
}, 500 ) | |
}) | |
clearInterval(readyMatch) | |
} | |
}, 500) | |
} | |
} catch (e) { | |
automationLogMessage("<span stle='color: red;'>"+a+"</span>") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment