Skip to content

Instantly share code, notes, and snippets.

@DennisdeBest
Created October 15, 2023 12:52
Show Gist options
  • Save DennisdeBest/1b243eaad86e3fcd661da14b7ff3d6a4 to your computer and use it in GitHub Desktop.
Save DennisdeBest/1b243eaad86e3fcd661da14b7ff3d6a4 to your computer and use it in GitHub Desktop.
Human Benchmark WPM
// ==UserScript==
// @name Human benchmark typing
// @version 1
// @grant none
// @match https://humanbenchmark.com/tests/typing
// ==/UserScript==
const typeText = async (text, targetDiv) => {
for (const ch of text) {
let event = new KeyboardEvent('keydown', {
'key': ch,
'code': `Key${ch.toUpperCase()}`,
'charCode': ch.charCodeAt(0),
'keyCode': ch.charCodeAt(0),
'bubbles': true,
'cancelable': true,
'which': ch.charCodeAt(0),
});
targetDiv.dispatchEvent(event);
await new Promise(resolve => setTimeout(resolve, 1));
}
};
const execute = () => {
const textDivs = document.getElementsByClassName('letters');
if (textDivs.length === 0) {
console.log("No text divs found.");
return;
}
const textDiv = textDivs[0];
let chars = '';
const childElements = textDiv.childNodes;
childElements.forEach((child) => {
if (child.innerHTML) {
chars += child.innerHTML;
}
});
if (textDiv) {
typeText(chars, textDiv);
} else {
console.log("No target div found.");
}
console.log(chars);
};
execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment