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.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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