Skip to content

Instantly share code, notes, and snippets.

@dylan-chong
Last active March 25, 2018 10:27
Show Gist options
  • Save dylan-chong/1409d67b7fc8a674caca4125e2a7fd03 to your computer and use it in GitHub Desktop.
Save dylan-chong/1409d67b7fc8a674caca4125e2a7fd03 to your computer and use it in GitHub Desktop.
Typeracer hack
// Run this in the console just before the countdown timer goes from "1" to "9"
// then wiggle the mouse over the text input
// (it helps if you zoom in in the browser to increase the input element size)
var charsPerIteration = 5;
var maxPressesPerSecond = 32;
var charsBeforeBackoff = 20;
var backoffDelayPerChar = 50;
var textElems = [].slice.call($("[unselectable='on']").parentNode.children);
var content = textElems.map(function (e) { return e.innerHTML; }).join('');
var input = $('.txtInput');
var startTime = void 0;
var keyPresses = 0;
setTimeout(function () {
startTime = Date.now();
write(content);
}, 1000);
function write(text, index) {
if (index === void 0) index = 0;
if (index >= text.length) return;
input.focus();
input.select();
for (var i = 0; i < charsPerIteration && i < text.length; i++) {
input.value += text[index + i];
keyPresses++;
}
setTimeout(function () {
write(text, index + charsPerIteration);
}, delay());
function delay() {
var pressesPerSecond = 1000 * keyPresses / (Date.now() - startTime);
// pps = wpm*5.1/60, where 5.1 is avg word length
console.log("wpm: " + (pressesPerSecond * 60 / 5.1));
if (keyPresses > charsBeforeBackoff
&& pressesPerSecond > maxPressesPerSecond) {
return backoffDelayPerChar * charsPerIteration;
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment