MonkeyType AutoTyper Bot

A Bot that automatically types for you in MokeyType.

目前为 2023-05-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name MonkeyType AutoTyper Bot
  3. // @author longkidkoolstar
  4. // @description A Bot that automatically types for you in MokeyType.
  5. // @icon https://th.bing.com/th/id/R.c8397fb766c4397fea8a8b499c15a453?rik=aROX42RoH7HhXw&pid=ImgRaw&r=0
  6. // @version 1.01
  7. // @match *://monkeytype.com/*
  8. // @run-at document-start
  9. // @grant none
  10. // @license MIT
  11. // @namespace https://greasyfork.org/users/1000020
  12. // ==/UserScript==
  13. /* jshint esversion:6 */
  14.  
  15.  
  16. //Credit to Murka007 for providing the foundation code for this wouldn't have been able to do this without you. Sorry, I didn't ask for perms just wanted to post this fast please don't report.
  17. //If you want me to take it down, Dm me at kdkoolstar#3114. Please and thank you. Enjoy the script!!!
  18.  
  19.  
  20. (function() {
  21. "use strict";
  22.  
  23. // Minimum and maximum delay (ms)
  24. let MIN_DELAY = 100;
  25. let MAX_DELAY = 333;
  26. const TOGGLE_KEY = "ArrowRight";
  27. const log = console.log;
  28.  
  29. function random(min, max) {
  30. return Math.floor(Math.random() * (max - min + 1) + min);
  31. }
  32.  
  33. let toggle = false;
  34. function canType() {
  35. const typingTest = document.getElementById("typingTest");
  36. const isHidden = typingTest.classList.contains("hidden");
  37. if (isHidden) toggle = false;
  38. return toggle && !isHidden;
  39. }
  40.  
  41. function getNextCharacter() {
  42. const currentWord = document.querySelector(".word.active");
  43. for (const letter of currentWord.children) {
  44. if (letter.className === "") return letter.textContent;
  45. }
  46. return " ";
  47. }
  48.  
  49. const InputEvents = {};
  50. function pressKey(key) {
  51. const wordsInput = document.getElementById("wordsInput");
  52. const KeyboardEvent = Object.assign({}, DEFAULT_INPUT_OPTIONS, { target: wordsInput, data: key });
  53. const InputEvent = Object.assign({}, DEFAULT_KEY_OPTIONS, { target: wordsInput, key: key });
  54.  
  55. wordsInput.value += key;
  56. InputEvents.beforeinput(InputEvent);
  57. InputEvents.input(InputEvent);
  58. InputEvents.keyup(KeyboardEvent);
  59. }
  60.  
  61. function typeCharacter() {
  62. if (!canType()) {
  63. log("STOPPED TYPING TEST");
  64. return;
  65. }
  66.  
  67. const nextChar = getNextCharacter();
  68.  
  69. // introduce some random errors
  70. const errorChance = 0.05; // 5% chance of an error
  71. if (Math.random() < errorChance) {
  72. // skip this character
  73. setTimeout(typeCharacter, random(MIN_DELAY, MAX_DELAY));
  74. return;
  75. } else if (Math.random() < errorChance) {
  76. // repeat this character
  77. pressKey(nextChar);
  78. } else if (Math.random() < errorChance) {
  79. // insert a random incorrect character
  80. const randomChar = String.fromCharCode(random(97, 122)); // random lowercase letter
  81. pressKey(randomChar);
  82. }
  83.  
  84. // press the next character
  85. pressKey(nextChar);
  86.  
  87. // introduce a pause between words
  88. if (nextChar === " ") {
  89. const pauseDelay = random(500, 1500); // pause for 0.5 to 1.5 seconds
  90. setTimeout(typeCharacter, pauseDelay);
  91. } else {
  92. setTimeout(typeCharacter, random(MIN_DELAY, MAX_DELAY));
  93. }
  94. }
  95.  
  96. window.addEventListener("keydown", function(event) {
  97. if (event.code === TOGGLE_KEY) {
  98. event.preventDefault();
  99.  
  100. if (event.repeat) return;
  101. toggle = !toggle;
  102. if (toggle) {
  103. log("STARTED TYPING TEST");
  104. typeCharacter();
  105. }
  106. }
  107. })
  108.  
  109. // Intercept when JQuery attached an addEventListener to the Input element
  110. function hook(element) {
  111. element.addEventListener = new Proxy(element.addEventListener, {
  112. apply(target, _this, args) {
  113. const [type, listener, ...options] = args;
  114. if (_this.id === "wordsInput") {
  115. InputEvents[type] = listener;
  116. }
  117. return target.apply(_this, args);
  118. }
  119. })
  120. }
  121. hook(HTMLInputElement.prototype);
  122.  
  123. const DEFAULT_KEY_OPTIONS = {
  124. key: "", code: "", keyCode: 0, which: 0, isTrusted: true, altKey: false,
  125. bubbles: true, cancelBubble: false, cancelable: true, charCode: 0,
  126. composed: true, ctrlKey: false, currentTarget: null, defaultPrevented: false,
  127. detail: 0, eventPhase: 0, isComposing: false, location: 0, metaKey: false,
  128. path: null, repeat: false, returnValue: true, shiftKey: false, srcElement: null,
  129. target: null, timeStamp: 6338.5, type: "", view: window,
  130. };
  131.  
  132. const DEFAULT_INPUT_OPTIONS = {
  133. isTrusted: true, bubbles: true, cancelBubble: false, cancelable: false,
  134. composed: true, data: "", dataTransfer: null, defaultPrevented: false,
  135. detail: 0, eventPhase: 0, inputType: "insertText", isComposing: false,
  136. path: null, returnValue: true, sourceCapabilities: null, srcElement: null,
  137. target: null, currentTarget: null, timeStamp: 11543, type: "input",
  138. view: null, which: 0
  139. };
  140.  
  141. // Add GUI to change min and max delay
  142. const gui = document.createElement("div");
  143. gui.style.position = "fixed";
  144. gui.style.bottom = "50%";
  145. gui.style.right = "0";
  146. gui.style.transform = "translateY(50%)";
  147. gui.style.padding = "5px";
  148. gui.style.background = "rgba(0, 0, 0, 0.6)";
  149. gui.style.color = "white";
  150. gui.style.fontFamily = "sans-serif";
  151. gui.style.fontSize = "12px";
  152. gui.innerHTML = `
  153. <div style="display: flex; flex-direction: column; align-items: center; justify-content: center;">
  154. <div style="margin-bottom: 5px;">
  155. Min Delay: <input type="number" id="minDelayInput" value="${MIN_DELAY}" min="0" max="1000" step="10" style="width: 40px;">
  156. </div>
  157. <div>
  158. Max Delay: <input type="number" id="maxDelayInput" value="${MAX_DELAY}" min="0" max="1000" step="10" style="width: 40px;">
  159. </div>
  160. </div>
  161. `;
  162. document.body.appendChild(gui);
  163.  
  164. const minDelayInput = document.getElementById("minDelayInput");
  165. const maxDelayInput = document.getElementById("maxDelayInput");
  166.  
  167. minDelayInput.addEventListener("input", function() {
  168. MIN_DELAY = parseInt(minDelayInput.value);
  169. });
  170.  
  171. maxDelayInput.addEventListener("input", function() {
  172. MAX_DELAY = parseInt(maxDelayInput.value);
  173. });
  174.  
  175. // Add event listener to prevent keydown event from propagating to Monkeytype
  176. minDelayInput.addEventListener("keydown", (event) => {
  177. event.stopPropagation();
  178. });
  179.  
  180. maxDelayInput.addEventListener("keydown", (event) => {
  181. event.stopPropagation();
  182. });
  183.  
  184. })();