// ==UserScript==
// @name sascacci 自动点击器
// @name:en sascacci.com Auto presser
// @namespace Violentmonkey Scripts
// @match https://sascacci.com/touchwaves/*
// @grant GM_log
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_addValueChangeListener
// @version 0.3.1
// @author axototl
// @license AGPL-3.0-or-later
// @run-at document-idle
// @description 自动点击,解放你的双手!
// @description:en An auto presser to release your hands !!!
// ==/UserScript==
'use strict';
const codecs = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 109, 110, 111, 32];
const len = codecs.length;
function getValue(name, def) {
let t = GM_getValue(name);
if (null == t) {
t = def;
GM_setValue(name, t);
}
return t;
}
let dbg = getValue("debug", false);
const canvas = document.getElementById("cvsID");
let keeptime = getValue("keeptime", 3500);
function press(key) {
const conf = {
bubbles: true,
cancelable: true,
keyCode: key
};
const ke = new KeyboardEvent('keydown', conf);
const ku = new KeyboardEvent('keyup', conf);
canvas.dispatchEvent(ke);
const kutime = random(keeptime)+100;
setTimeout(() => canvas.dispatchEvent(ku), kutime);
if (dbg) {
GM_log(key, "pressed!");
console.debug("keep times:", kutime);
}
}
function random(max_plus_1) {
const arr = new Uint32Array(1);
crypto.getRandomValues(arr);
return arr[0] % max_plus_1;
}
function getRand() {
const r = random(len);
return codecs[r];
}
let stop = false;
async function main () {
if (stop) return;
const cdc = getRand();
press(cdc);
setTimeout(main, 1000);
}
(() => {
if (getValue("first", true)) {
alert("Click any place to Start!\n 点击任意一处开始自动播放");
GM_setValue("first", false);
}
canvas.addEventListener("click", listen);
function listen(ev) {
canvas.removeEventListener("click", listen);
main();
}
})();
(() => {
const props = ["✅ (Enabled) ", "❌ (Disabled) "];
function reg_dbg() {
return GM_registerMenuCommand(props[dbg | 0] + "调试模式 (Debug)", () => GM_setValue("debug", !dbg));
}
let tmp2 = reg_dbg();
GM_addValueChangeListener("debug", (_1, _2, nv, _3) => {
GM_unregisterMenuCommand(tmp2);
dbg = nv;
tmp2 = reg_dbg();
});
const tmp = GM_registerMenuCommand("停止运行 (Stop)", () => {
stop = true;
GM_unregisterMenuCommand(tmp);
GM_unregisterMenuCommand(tmp2);
});
GM_registerMenuCommand("设置按键持续时间 (Hold Time)", () => {
let t;
do {
t = window.prompt("请输入需要的持续时间 (ms),\n 小于0的数会被忽略\n Ignore input if input is negative.");
} while (isNaN(t));
if (t < 0) t = 0;
GM_setValue("keeptime", t);
});
GM_addValueChangeListener("keeptime", (_1, _2, nv) => keeptime = nv);
})();