CTRL+Click Auto-Clicker (100ms)

Starts auto-clicking at 100ms intervals on the element clicked with CTRL (or ⌘) + Left Click. Stops with a normal click or ESC.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         CTRL+Click Auto-Clicker (100ms)
// @namespace    https://tr-wp.com/
// @version      1.0
// @description  Starts auto-clicking at 100ms intervals on the element clicked with CTRL (or ⌘) + Left Click. Stops with a normal click or ESC.
// @author       Yoka - tr-wp.com
// @match        *://*/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    let intervalId = null;
    let targetElement = null;
    let originalOutline = null;

    function simulateClick(el) {
        if (!el) return;
        
        const rect = el.getBoundingClientRect();
        const clientX = rect.left + rect.width / 2;
        const clientY = rect.top + rect.height / 2;

        const createMouseEvent = (type) => new MouseEvent(type, {
            bubbles: true,
            cancelable: true,
            view: window,
            clientX,
            clientY,
            button: 0
        });

        el.dispatchEvent(createMouseEvent('mousedown'));
        el.dispatchEvent(createMouseEvent('mouseup'));
        el.dispatchEvent(createMouseEvent('click'));
    }

    function startAutoClicking(el) {
        stopAutoClicking();

        targetElement = el;
        originalOutline = el.style.outline || '';
        el.style.outline = '2px solid red';

        intervalId = setInterval(() => {
            if (!document.contains(targetElement)) {
                stopAutoClicking();
                return;
            }
            simulateClick(targetElement);
        }, 100);
    }

    function stopAutoClicking() {
        if (intervalId !== null) {
            clearInterval(intervalId);
            intervalId = null;
            if (targetElement) {
                try { 
                    targetElement.style.outline = originalOutline; 
                } catch(e) {}
            }
            targetElement = null;
            originalOutline = null;
        }
    }

    window.addEventListener('mousedown', function(e) {
        if (!e.isTrusted) return;
        if ((e.button === 0) && (e.ctrlKey || e.metaKey)) {
            startAutoClicking(e.target);
        }
    }, true);

    window.addEventListener('click', function(e) {
        if (!e.isTrusted) return;
        if (intervalId !== null) {
            if (!(e.ctrlKey || e.metaKey)) {
                stopAutoClicking();
            }
        }
    }, true);

    window.addEventListener('keydown', function(e) {
        if (e.key === 'Escape' || e.key === 'Esc') {
            stopAutoClicking();
        }
    });

    window.addEventListener('beforeunload', stopAutoClicking);
})();