// ==UserScript==
// @name mtgbrr
// @author natsukitheslashuser
// @description press slash and start typing, it'll save a result. dont have to press slash again and again if you didn't complete the test. you need to press slash if you completed the test. (ts fire)
// @icon https://i.imgur.com/fUjylt3.png
// @version 6.9
// @match *://monkeytype.com/*
// @run-at document-start
// @grant none
// @license me hehe
// @namespace natsuki
// ==/UserScript==
(function() {
"use strict";
const d1=60, d2=60, tg="Slash", mpm=5, s=1, log=console.log;
let on=false, t1=null, t2=null, l=0, r=0, a=0, m=0, t=0, y=false;
function rdm(a, b) { return Math.floor(Math.random() * (b - a + 1) + a); }
function chk() {
const e = document.getElementById("typingTest");
return e && !e.classList.contains("hidden") && on && y;
}
function nxt() {
const e = document.querySelector(".word.active");
if (!e) return "";
for (const t of e.children) if (t.className === "") return t.textContent;
return " ";
}
function err() {
const elapsed = (Date.now() - t) / 60000 * mpm;
if (m < elapsed) {
const remTime = 60 - (elapsed * 60 % 60), remMistakes = Math.ceil(mpm - m % mpm);
return Math.random() < (remMistakes / (remTime * 2));
}
return false;
}
function wrg(e) {
const t = { a: ["s", "q", "z", "w"], b: ["v", "n", "g", "h"], c: ["x", "v", "d", "f"], d: ["s", "f", "e", "r"], e: ["w", "r", "d", "f"], f: ["d", "g", "r", "t"], g: ["f", "h", "t", "y"], h: ["g", "j", "y", "u"], i: ["u", "o", "k", "l"], j: ["h", "k", "u", "i"], k: ["j", "l", "i", "o"], l: ["k", ";", "o", "p"], m: ["n", ",", "j", "k"], n: ["b", "m", "h", "j"], o: ["i", "p", "k", "l"], p: ["o", "[", "l", ";"], q: ["w", "a", "1", "2"], r: ["e", "t", "d", "f"], s: ["a", "d", "w", "e"], t: ["r", "y", "f", "g"], u: ["y", "i", "h", "j"], v: ["c", "b", "f", "g"], w: ["q", "e", "a", "s"], x: ["z", "c", "s", "d"], y: ["t", "u", "g", "h"], z: ["a", "x", "s", "d"], " ": ["n", "m", "b", "v"] };
return e in t ? t[e][Math.floor(Math.random() * t[e].length)] : String.fromCharCode(e.charCodeAt(0) + (Math.random() > .5 ? 1 : -1));
}
const ev = {};
function press(e) {
const t = document.getElementById("wordsInput");
if (!t) return;
t.value += e;
ev.beforeinput?.({ target: t, key: e });
ev.input?.({ target: t, key: e });
ev.keyup?.({ target: t, key: e });
a++;
if (a % 10 == 0) log(`A:${a},R:${r},M:${m}`);
}
function stop() {
if (t2) clearInterval(t2);
t2 = setInterval(() => {
if (Date.now() - l > s && y) {
y = false;
if (t1) { clearTimeout(t1); t1 = null; }
}
}, 1);
}
function type() {
if (t1) { clearTimeout(t1); t1 = null; }
if (!chk()) return;
const e = nxt();
if (e) {
err() ? (press(wrg(e)), m++, log(`MISTAKE: '${wrg(e)}' instead of '${e}' (${m})`)) : press(e);
if (chk()) t1 = setTimeout(type, rdm(d1, d2));
}
}
window.addEventListener("keydown", function(e) {
if (e.code === tg) {
e.preventDefault();
if (e.repeat) return;
on = !on;
if (on) {
r = a = m = 0;
t = Date.now();
log("ON");
stop();
} else {
log("OFF");
if (t1) { clearTimeout(t1); t1 = null; }
if (t2) { clearInterval(t2); t2 = null; }
y = false;
}
} else if (on && !["Control", "Alt", "Shift", "Meta", "CapsLock", "Tab", "Escape"].includes(e.key)) {
r++;
l = Date.now();
y = true;
if (!t1) type();
e.preventDefault();
}
}, true);
window.addEventListener("beforeunload", () => { if (t1) clearTimeout(t1); if (t2) clearInterval(t2); });
function hook(e) {
e.addEventListener = new Proxy(e.addEventListener, {
apply(t, n, o) {
const [i, c, ...s] = o;
if (n.id === "wordsInput") ev[i] = c;
return t.apply(n, o);
}
});
}
hook(HTMLInputElement.prototype);
log("Loaded - Press / to toggle, then type to activate");
})();