Created
June 6, 2020 23:36
-
-
Save zavan/9ec5fc5e177698e6b3f504bb30241043 to your computer and use it in GitHub Desktop.
Fooling typingtest.com and breaking records
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
let time = 10; // Increase this if you're getting typing errors | |
function pressKey(key, code, eventType = 'keypress') { | |
console.log(`Typing "${key}" (${code}) with event ${eventType}`); | |
let event = new KeyboardEvent(eventType, { | |
key: key, | |
keyCode: code, | |
which: code, | |
charCode: code | |
}); | |
let el = document.getElementById('test-edit-area'); | |
el.dispatchEvent(event); | |
} | |
let i = 0; | |
$('.test-text-area').children().each(function() { | |
const word = $(this).text(); | |
word.split('').forEach((char, j) => { | |
let charCode = char.charCodeAt(0); | |
let key = char; | |
if (char === '↩') { | |
charCode = 13; | |
key = 'Enter'; | |
} | |
setTimeout(() => { | |
pressKey(key, charCode, charCode === 13 ? 'keydown' : 'keypress'); // Return only works with keydown | |
if (j === word.length-1) { | |
// End of the word, type space | |
setTimeout(() => { | |
pressKey('Space', 32, 'keydown'); // Space only works with keydown | |
}, time); | |
} | |
}, i*time*3); | |
i++; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Open a text test page on typingtest.com and run this script on the browser console (tested on Safari). This will read and simulate pressing each key.