AutoClick

Hold ` key to repeatedly click element under mouse

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        AutoClick
// @author      QtheConqueror
// @namespace   Automation
// @description Hold ` key to repeatedly click element under mouse
// @version     3.0
// @include     http:*
// @include     https:*
// @grant       none
// @license     GPL-3.0-or-later
// ==/UserScript==

var cps = 0; // Clicks per Second: 0 = as fast as possible

if (window.attachEvent) {
    document.attachEvent('onmousemove', mouseMv);
} else {
    document.addEventListener('mousemove', mouseMv, false);
}
document.addEventListener('keydown', keyDown);

var x, y;
var interval, timeout;
var rate = (cps ? 1000 / (cps / 3) : 0);

/**
 * Summary: Listens for mouse movement and exports position to variables x & y.
 * @param {Event} e 
 */
function mouseMv(e) {
    if (!e) e = window.event;

    if (typeof e.pageY == 'number') {
        x = e.pageX;
        y = e.pageY;
    } else {
        x = e.clientX;
        y = e.clientY;
    }
}

/**
 * Summary: Listens for keydown event
 * @param {Event} e 
 */
function keyDown(e) {``
    var char = e.key
    if (char == '`' || char == '~') {
        interval = setInterval(click, rate, x, y);
        timeout = setTimeout(clearInterval, 200, interval)
    }
}

/** 
 * Summary: Clicks element at positions (x, y) on document.
 * @param {number} x - X coordinate of document element.
 * @param {number} y - Y coordinate of document element.
 */
function click() {
    document.elementFromPoint(x, y).click();
}