Automates typing wihtout automating pressing space on website typewriter
当前为
// ==UserScript==
// @name Typhacker
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Automates typing wihtout automating pressing space on website typewriter
// @author random russian guy
// @match https://sg.typewriter.ch/index.php?r=typewriter/runLevel
// @license MIT
// @grant none
// ==/UserScript==
(function() {
'use strict';
const VALID_CHAR_REGEX = /^[a-zA-Z0-9À-ÖØ-öø-ÿ.,:;!?@#$%^&*()_+\-=\[\]{}|\\:;"'<>,.? ]$/;
function detectAndType() {
const spans = document.querySelectorAll('span');
spans.forEach(span => {
const text = span.textContent.trim();
if (text.length === 1 && VALID_CHAR_REGEX.test(text)) {
typeCharacter(text);
}
});
}
function typeCharacter(char) {
const typingArea = document.activeElement;
if (typingArea && (typingArea.tagName === 'INPUT' || typingArea.tagName === 'TEXTAREA')) {
const eventOptions = {
key: char,
code: `Key${char.toUpperCase()}`,
char: char,
keyCode: char.charCodeAt(0),
which: char.charCodeAt(0),
bubbles: true,
cancelable: true
};
typingArea.dispatchEvent(new KeyboardEvent('keydown', eventOptions));
typingArea.dispatchEvent(new KeyboardEvent('keypress', eventOptions));
typingArea.dispatchEvent(new KeyboardEvent('keyup', eventOptions));
}
}
function delayedDetectAndType() {
detectAndType();
}
setInterval(delayedDetectAndType, 100);
})();