Human-Typer by Warrior

Simulate human typing in Google Docs and Slides with customizable settings such as typing speed, errors, and breaks.

目前为 2024-04-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Human-Typer by Warrior
  3. // @description Simulate human typing in Google Docs and Slides with customizable settings such as typing speed, errors, and breaks.
  4. // @version 1.1
  5. // @namespace http://yournamespace.com/human-typer
  6. // @match *://docs.google.com/document/*
  7. // @match *://docs.google.com/presentation/*
  8. // @include *://docs.google.com/document/*
  9. // @include *://docs.google.com/presentation/*
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Constants for typing speeds
  17. const typingSpeeds = {
  18. fast: { lower: 50, upper: 150 },
  19. medium: { lower: 60, upper: 220 },
  20. normal: { lower: 70, upper: 200 },
  21. slow: { lower: 80, upper: 240 }
  22. };
  23.  
  24. // Variables
  25. let typingInProgress = false;
  26. let cancelTyping = false;
  27.  
  28. // Create the "Human Typer" button
  29. const createHumanTyperButton = () => {
  30. const button = document.createElement('button');
  31. button.textContent = 'Human Typer';
  32. button.style.position = 'fixed';
  33. button.style.bottom = '10px';
  34. button.style.right = '10px';
  35. button.style.backgroundColor = 'black';
  36. button.style.color = 'white';
  37. button.style.padding = '10px';
  38. button.style.border = 'none';
  39. button.style.borderRadius = '5px';
  40. button.style.cursor = 'pointer';
  41. button.addEventListener('click', showOverlay);
  42. document.body.appendChild(button);
  43. };
  44.  
  45. // Function to display the overlay for user input
  46. const showOverlay = () => {
  47. // Create overlay elements
  48. const overlay = document.createElement('div');
  49. overlay.style.position = 'fixed';
  50. overlay.style.bottom = '10px';
  51. overlay.style.right = '10px';
  52. overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
  53. overlay.style.padding = '10px';
  54. overlay.style.borderRadius = '5px';
  55. overlay.style.zIndex = '9999';
  56. const textarea = document.createElement('textarea');
  57. textarea.placeholder = 'Enter your text...';
  58. textarea.style.width = '200px';
  59. textarea.style.height = '100px';
  60. textarea.style.marginBottom = '10px';
  61.  
  62. const speedSelect = document.createElement('select');
  63. for (const speed in typingSpeeds) {
  64. const option = document.createElement('option');
  65. option.value = speed;
  66. option.textContent = speed.charAt(0).toUpperCase() + speed.slice(1);
  67. speedSelect.appendChild(option);
  68. }
  69.  
  70. const startButton = document.createElement('button');
  71. startButton.textContent = 'Start';
  72. startButton.addEventListener('click', () => {
  73. const speed = speedSelect.value;
  74. const userText = textarea.value.trim();
  75. overlay.remove();
  76. startTyping(userText, speed);
  77. });
  78.  
  79. // Append elements to overlay
  80. overlay.appendChild(textarea);
  81. overlay.appendChild(speedSelect);
  82. overlay.appendChild(startButton);
  83. document.body.appendChild(overlay);
  84. };
  85.  
  86. // Function to start typing with the selected speed
  87. const startTyping = (text, speed) => {
  88. if (typingInProgress) return;
  89.  
  90. const speedValues = typingSpeeds[speed] || typingSpeeds.normal;
  91. const iframe = document.querySelector('.docs-texteventtarget-iframe');
  92. const activeElement = iframe.contentDocument.activeElement;
  93.  
  94. typingInProgress = true;
  95.  
  96. // Simulate typing
  97. (async () => {
  98. for (let i = 0; i < text.length; i++) {
  99. if (cancelTyping) break;
  100.  
  101. activeElement.value += text[i];
  102. await new Promise(resolve => setTimeout(resolve, Math.random() * (speedValues.upper - speedValues.lower) + speedValues.lower));
  103.  
  104. // Simulate mistakes
  105. if (Math.random() < 0.05) {
  106. activeElement.value += text[i]; // Add a mistake
  107. await new Promise(resolve => setTimeout(resolve, Math.random() * (speedValues.upper - speedValues.lower) + speedValues.lower));
  108. activeElement.value = activeElement.value.slice(0, -1); // Correct the mistake
  109. }
  110. }
  111.  
  112. typingInProgress = false;
  113. })();
  114. };
  115.  
  116. // Initialize the Human Typer button
  117. createHumanTyperButton();
  118.  
  119. })();