Created
October 15, 2023 12:52
-
-
Save DennisdeBest/1b243eaad86e3fcd661da14b7ff3d6a4 to your computer and use it in GitHub Desktop.
Human Benchmark WPM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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