Skip to content

Instantly share code, notes, and snippets.

@zavan
Created June 6, 2020 23:36
Show Gist options
  • Save zavan/9ec5fc5e177698e6b3f504bb30241043 to your computer and use it in GitHub Desktop.
Save zavan/9ec5fc5e177698e6b3f504bb30241043 to your computer and use it in GitHub Desktop.
Fooling typingtest.com and breaking records
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++;
});
});
@zavan
Copy link
Author

zavan commented Jun 6, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment