Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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