Auto Typer for Typing.com

Typing.com Bot: AutoType Up to 300 WPM

  1. // ==UserScript==
  2. // @name Auto Typer for Typing.com
  3. // @match https://www.typing.com/
  4. // @match https://www.typing.com/*
  5. // @author Sing Developments/Rahul Bellam
  6. // @grant none
  7. // @description Typing.com Bot: AutoType Up to 300 WPM
  8. // @license MIT
  9. // @version 4
  10. // @namespace https://typing.com/
  11. // @icon https://images.saasworthy.com/typingcom_5788_logo_1579674673_vc5lj.jpg
  12. // ==/UserScript==
  13.  
  14.  
  15.  
  16. // NOTE: When delay (in ms between two strokes) is too low, the site might bug out and the result page will not be shown
  17. const minDelay = 60;
  18. const maxDelay = 60;
  19.  
  20.  
  21.  
  22. const keyOverrides = {
  23. [String.fromCharCode(160)]: ' ' // convert hardspace to normal space
  24. };
  25.  
  26. function getTargetCharacters() {
  27. const els = Array.from(document.querySelectorAll('.token span.token_unit'));
  28. const chrs = els
  29. .map(el => {
  30. // get letter to type from each letter DOM element
  31. if (el.firstChild?.classList?.contains('_enter')) {
  32. // special case: ENTER
  33. return '\n';
  34. }
  35. let text = el.textContent[0];
  36. return text;
  37. })
  38. .map(c => keyOverrides.hasOwnProperty(c) ? keyOverrides[c] : c); // convert special characters
  39. return chrs;
  40. }
  41.  
  42. function recordKey(chr) {
  43. // send it straight to the internal API
  44. window.core.record_keydown_time(chr);
  45. }
  46.  
  47. function sleep(ms) {
  48. return new Promise(r => setTimeout(r, ms));
  49. }
  50.  
  51. async function autoPlay(finish) {
  52. const chrs = getTargetCharacters();
  53. for (let i = 0; i < chrs.length - (!finish); ++i) {
  54. const c = chrs[i];
  55. recordKey(c);
  56. //console.log(c, c.charCodeAt());
  57. await sleep(Math.random() * (maxDelay - minDelay) + minDelay);
  58. }
  59. }
  60.  
  61. // ############################################################################################################
  62. // old utilities
  63. // ############################################################################################################
  64.  
  65.  
  66. // /**
  67. // * @see https://stackoverflow.com/questions/8942678/keyboardevent-in-chrome-keycode-is-0/12522752#12522752
  68. // */
  69. // function simulateKey(chr, el) {
  70. // _simulateKey(chr, 'keydown', el);
  71. // _simulateKey(chr, 'keypress', el);
  72. // }
  73. // function _simulateKey(chr, type, el) {
  74. // var eventObj = document.createEventObject ?
  75. // document.createEventObject() : document.createEvent("Events");
  76.  
  77. // if (eventObj.initEvent) {
  78. // eventObj.initEvent(type || "keydown", true, true);
  79. // }
  80.  
  81. // let keyCode = chr.charCodeAt(0);
  82.  
  83. // eventObj.key = chr[0];
  84. // eventObj.keyCode = keyCode;
  85. // eventObj.which = keyCode;
  86. // eventObj.isTrusted = true;
  87.  
  88. // el = el || document.body;
  89.  
  90. // // console.log(keyCode, eventObj);
  91.  
  92. // el.dispatchEvent ? el.dispatchEvent(eventObj) : el.fireEvent("onkeydown", eventObj);
  93. // }
  94.  
  95. // document.addEventListener("keydown", function (e) {
  96. // console.log('down', e);
  97. // });
  98. // document.addEventListener("keypress", function (e) {
  99. // console.log('press', e);
  100. // });
  101. //$($('.menu-btn')[0].parentNode).prepend('<button onclick=\'simulateKeyPress("c")\'>sim</button>');
  102. // simulateKey('a', $('input')[0]);
  103.  
  104.  
  105.  
  106. // ############################################################################################################
  107. // go!
  108. // ############################################################################################################
  109.  
  110. autoPlay(true);