10fastfingers hack

Simulate typing and auto correct

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         10fastfingers hack
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Simulate typing and auto correct
// @license      MIT
// @author       kyzsuki
// @match        https://10fastfingers.com/typing-test/*
// @match        https://typingtop.com/**/typing-test
// @grant        none
// ==/UserScript==

(function () {
  "use strict";

  var word_idx = 0;
  var letter_idx = 0;
  var interval_per_word = 250;
  var maxTypoCount = Math.floor(Math.random() * (16 - 7 + 1)) + 7;
  var currentTypoCount = 0;

  var typingInterval;
  var word;

  var isTyping = false;

  function typing() {
    var interval_per_letter = Math.floor(Math.random() * (130 - 110 + 1)) + 110;

    if (countdown <= 0) {
      clearTimeout(typingInterval);
      isTyping = false;
      // word_idx = 0;
      return;
    }

    if (word_idx < words.length) {
      word = words[word_idx];
      if (letter_idx < word.length) {
        var letter = word[letter_idx];
        if (Math.random() < 0.1 && currentTypoCount < maxTypoCount) {
          letter = String.fromCharCode(97 + Math.floor(Math.random() * 26));
          currentTypoCount++;
        }
        $("#inputfield").val($("#inputfield").val() + letter);
        letter_idx++;
        typingInterval = setTimeout(typing, interval_per_letter);
      } else {
        var keyup = jQuery.Event("keyup");
        keyup.which = 32;
        $("#inputfield").trigger(keyup);
        word_idx++;
        letter_idx = 0;
        if (word_idx < words.length) {
          typingInterval = setTimeout(typing, interval_per_word);
        }
      }
    }
  }

  function autoCorrect() {
    if (word_idx < words.length) {
      word = words[word_idx];
      if (letter_idx < word.length) {
        var letter = word[letter_idx];
        if (Math.random() < 0.1 && currentTypoCount < maxTypoCount) {
          letter = String.fromCharCode(97 + Math.floor(Math.random() * 26));
          currentTypoCount++;
        }
        $("#inputfield").val($("#inputfield").val() + letter);
        letter_idx++;
      } else {
        var keyup = jQuery.Event("keyup");
        keyup.which = 32;
        $("#inputfield").trigger(keyup);
        word_idx++;
        letter_idx = 0;
      }
    }
  }

  $(document).on("keydown", function (event) {
    event.preventDefault();
    if (!isTyping) {
      isTyping = true;
      autoCorrect();
      isTyping = false;
    }
  });

  document.addEventListener("keydown", function (e) {
    if (isTyping) {
      e.preventDefault();
    }
  });

  $("#inputfield").on("focus mouseover", function (e) {
    if (isTyping) {
      e.preventDefault();
    }
  });

  document.addEventListener("keydown", function (e) {
    if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.code === "KeyZ") {
      isTyping = true;
      typingInterval = setTimeout(typing, interval_per_word);
    }
  });
})();