Created
June 6, 2023 08:39
-
-
Save kadiks/526a59737be59d3d394896cb50378836 to your computer and use it in GitHub Desktop.
Impress your friends by typing fast in 10fastfingers.com
This file contains hidden or 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
function delay(ts = 100) { | |
return new Promise((resolve) => { | |
setTimeout(resolve, ts) | |
}) | |
} | |
async function typeWord({ word, delayMs = 300 } = {}) { | |
if (!word) { | |
console.log('Word is undefined') | |
} | |
const inputEl = document.querySelector('#inputfield') | |
if (!inputEl) { | |
console.log('Input does not exist') | |
} | |
const splitWord = word.split('') | |
for (let letter of splitWord) { | |
inputEl.value += letter | |
await delay(delayMs) | |
} | |
inputEl.value += " " | |
// https://stackoverflow.com/a/3368599/185771 | |
const kEvent = new Event('keyup') | |
kEvent.which = 32; | |
inputEl.dispatchEvent(kEvent); | |
} | |
async function typeFast({typeSpeed = 600, delayMs = 3000 } = {}) { | |
const currentElement = document.querySelector('#row1 .highlight'); | |
if (!currentElement) { | |
console.log("This element does not exist. End of game?") | |
} | |
const currentWord = currentElement.textContent | |
await typeWord({ word: currentWord, delayMs : typeSpeed }) | |
await delay(delayMs) | |
typeFast({ typeSpeed, delayMs }) | |
} | |
// Uncomment to run | |
// typeFast({typeSpeed: 20, delayMs: 100}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment