If you have ever heard of âwords per minuteâ (WPM), you have probably already tested your typing speed. Youâve also compared it to other people around the world in a competition, where the one who types the fastest 100 of the most common words in a language within a given time wins.
Well, chances are youâve already met a person exceeding 300 words per minute, and most likely cheating. The most effective way to counter that is maybe⌠to cheat too.
â Disclaimer: I donât encourage cheating, as it ruins the player experience. However, there are non-multiplayer modes that have no negative consequences on other people.
With that out of the way, letâs begin by analyzing how these sites work. For most of them, an algorithm highlights a word from a generated text so that you type it in an input as fast as possible, as shown below.
For the sake of this article, Iâll take the 10fastfingers.com website as an example. To execute the code weâll produce, download a userscript manager such as Tampermonkey, click on the add-on logo and âCreate a new scriptâ.
Great! Everything is setup. The first thing we should do is to create a function, which will be waiting for the highlighted word to show up. This can be easily done with a setInterval()
method.
function awaitElement() {
let interval = setInterval(function() {
if (document.getElementsByClassName("highlight")[0]) {
clearInterval(interval);
searchNewWord();
}
}, 100);
}
Here, we try to get the âhighlightâ element to see whether it exists on the document or not. Once it is found, the interval is cleared and another function is called.
Okay, we successfully managed to get the highlighted word, but apart from that, nothing happens. Now what?
Well, time to create our second function, named searchNewWord()
function searchNewWord() {
let interval = setInterval(function() {
let word = document.getElementsByClassName("highlight")[0].textContent;
document.getElementsByClassName("form-control")[0].value = word;
}, 100);
}
Another interval bytes the dust⌠haha�
In all seriousness, after getting the highlighted word content, the algorithm will search for the input and overwrite its content, every 100ms (0.1s).
Take a look below.
Here is the whole userscript file. You could also click here for the userscript to install automatically.
// ==UserScript==
// @name Typing race
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Try to type as fast as possible but with a bot help
// @author Mazz
// @match https://10fastfingers.com/*
// @icon https://www.google.com/s2/favicons?domain=10fastfingers.com
// @grant none
// ==/UserScript==(function () {
'use strict';awaitElement();function awaitElement() {
let interval = setInterval(function () {
if (document.getElementsByClassName("highlight")[0]) {
clearInterval(interval);
searchNewWord();
}
}, 100);
}function searchNewWord() {
let interval = setInterval(function () {
let word = document.getElementsByClassName("highlight")[0].textContent;
document.getElementsByClassName("form-control")[0].value = word;
}, 100);
}
})();
Thanks for reading! If this story helped you, consider sharing it to your friends đ