Skip to content

Instantly share code, notes, and snippets.

@isaacyakl
Last active January 5, 2023 17:33
Show Gist options
  • Save isaacyakl/9f6dadcc373b79c52adc705d990a351d to your computer and use it in GitHub Desktop.
Save isaacyakl/9f6dadcc373b79c52adc705d990a351d to your computer and use it in GitHub Desktop.
Tampermonkey script: Press 'Enter' to go to next race or to start a race; Press 'Esc' to return to the main menu
// ==UserScript==
// @name Better Keyboard Binds for TypeRacer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author yak (https://isaacyakl.com/)
// @match https://play.typeracer.com/
// @icon https://www.google.com/s2/favicons?sz=64&domain=typeracer.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
window.addEventListener("keydown", (e) => {
if(e.keyCode === 13) { // Enter
document.querySelector("#gwt-uid-1 > a") && document.querySelector("#gwt-uid-1 > a").click(); // Enter a typing race
document.querySelector(".raceAgainLink") && document.querySelector(".raceAgainLink").click(); // Race again
e.preventDefault(); // Protect from accidentally clicking a focused element when 'Enter' is pressed
}
else if(e.keyCode === 27) { // Esc
const mMenuBtn = Array.from(document.querySelectorAll("a")).find(n=>n.innerText==="Main menu (leave race)");
mMenuBtn && mMenuBtn.click(); // Main Menu (leave race)
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment