| | (function () {
|
| | console.log("%c Monkeytype Cheat Initiated ", "background: #222; color: #bada55; font-size: 20px");
|
| | function typeChar(char) {
|
| | const target = document.activeElement || document.body;
|
| | const key = char;
|
| | const code = `Key${char.toUpperCase()}`;
|
| | const eventOptions = {
|
| | key: key,
|
| | code: code,
|
| | charCode: char.charCodeAt(0),
|
| | keyCode: char.toUpperCase().charCodeAt(0),
|
| | which: char.toUpperCase().charCodeAt(0),
|
| | bubbles: true,
|
| | cancelable: true,
|
| | isTrusted: true
|
| | };
|
| | target.dispatchEvent(new KeyboardEvent('keydown', eventOptions));
|
| | target.dispatchEvent(new KeyboardEvent('keypress', eventOptions));
|
| |
|
| |
|
| | const inputEvent = new InputEvent('input', {
|
| | data: char,
|
| | inputType: 'insertText',
|
| | bubbles: true,
|
| | cancelable: true
|
| | });
|
| | target.dispatchEvent(inputEvent);
|
| |
|
| | target.dispatchEvent(new KeyboardEvent('keyup', eventOptions));
|
| | }
|
| | function cheat() {
|
| |
|
| | const activeWord = document.querySelector('#words .word.active');
|
| | const allWords = document.querySelectorAll('#words .word');
|
| |
|
| | if (!activeWord) {
|
| | console.error("Could not find active word. Is the test started?");
|
| | return;
|
| | }
|
| | let distinctText = "";
|
| | let foundActive = false;
|
| |
|
| | allWords.forEach(word => {
|
| | if (word === activeWord) {
|
| | foundActive = true;
|
| | }
|
| | if (foundActive) {
|
| |
|
| | const letters = word.querySelectorAll('letter');
|
| | letters.forEach(l => distinctText += l.textContent);
|
| |
|
| |
|
| | distinctText += " ";
|
| | }
|
| | });
|
| |
|
| |
|
| | const textToType = distinctText.substring(1);
|
| | console.log(`Typing ${textToType.length} characters... Buckle up!`);
|
| |
|
| |
|
| | for (let i = 0; i < textToType.length; i++) {
|
| | typeChar(textToType[i]);
|
| | }
|
| | }
|
| |
|
| | const triggerHandler = (e) => {
|
| | const activeWord = document.querySelector('#words .word.active');
|
| |
|
| | if (activeWord && e.key.length === 1 && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
| | const firstLetterElement = activeWord.querySelector('letter');
|
| | const firstLetter = firstLetterElement ? firstLetterElement.textContent : null;
|
| |
|
| |
|
| | if (firstLetter && e.key === firstLetter) {
|
| |
|
| | window.removeEventListener('keydown', triggerHandler);
|
| |
|
| |
|
| |
|
| | setTimeout(cheat, 10);
|
| | }
|
| | }
|
| | };
|
| | window.addEventListener('keydown', triggerHandler);
|
| |
|
| | console.log("READY: Type the first correct letter of the current word to auto-finish.");
|
| | })(); |