Last active
April 30, 2024 09:23
-
-
Save pierrelasse/db5a11effd797077ea134ccd00f8d95a to your computer and use it in GitHub Desktop.
typeracer.com cheat, hack, autotype
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
// Howto: | |
// Copy the code and put it in your developer console when on https://play.typeracer.com. | |
// It doesn't matter when you put the code in and it will stay loaded aslong as you don't reload the page. | |
// Just join a race and press enter to automaticly fill in the word. | |
// Todo: | |
// - Track on what word you currently are | |
// - Type each letter? | |
const trc = (cfg => { | |
const log = s => console.log("[TRC]", s); | |
log("Loading..."); | |
try { trc.unregister(); } catch { } | |
const a = { | |
log, | |
words: [], | |
index: 0, | |
inputElement: null, | |
cooldown: { | |
active: false, | |
start: (duration) => { | |
if (!trc.cooldown.active) { | |
trc.cooldown.active = true; | |
setTimeout(() => { | |
trc.cooldown.active = false; | |
}, duration); | |
} | |
} | |
}, | |
unregister: () => { | |
trc.log("Unregistering"); | |
document.removeEventListener("keypress", trc.keyPressHandler); | |
this.words = trc.words; | |
this.index = trc.index; | |
trc = null; | |
}, | |
getText: () => document.querySelector(".inputPanel tr:first-child")?.textContent || undefined, | |
refresh: () => { | |
trc.inputElement = document.getElementsByClassName("txtInput")[0]; | |
trc.words = trc.getText()?.split(" ") || []; | |
trc.index = 0; | |
trc.cooldown.active = false; | |
}, | |
getWpm: () => parseInt(document.querySelector("rankPanelWpm-self")?.innerText.split(" ")[0], 10), | |
}; | |
log("Creating handler"); | |
a.keyPressHandler = (ev) => { | |
if (ev.keyCode === (cfg.key || 13)) { | |
if (!trc.cooldown.active && trc.inputElement && trc.words && trc.index < trc.words.length) { | |
const wordToAdd = trc.words[trc.index] + (trc.index === trc.words.length - 1 ? "" : " "); | |
if (wordToAdd) { | |
ev.preventDefault(); | |
trc.inputElement.value = wordToAdd; | |
trc.index++; | |
if (cfg.cooldown > 0) { | |
trc.cooldown.start(cfg.cooldown || 120); | |
} | |
} | |
} else { | |
console.warn("[TRC] Not loaded correctly. Refreshing..."); | |
trc.refresh(); | |
} | |
} | |
if (cfg.debugKey) { | |
log(`The key ${ev.key} with keyCode ${ev.keyCode} was pressed`); | |
} | |
}; | |
log("Registering handler"); | |
document.addEventListener("keypress", a.keyPressHandler); | |
log("Done!"); | |
return a; | |
})({ | |
cooldown: 120, // The cooldown in ms for how fast you can press the key | |
key: 13, // The code if the key | |
debugKey: false // When a key was pressed, it print's its code to the console | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment