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.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);
})();