8.8 C
New York
Wednesday, October 16, 2024

javascript – Is there any method to simulate contact occasions on iOS units comparable to iPad?


I’ve coded it in order that whenever you run this, it prompts for cps, and generates a crimson dot as indicator the place you click on, I don’t imagine that that is working for ios, is there any method to make this work? That is meant to be ran as a bookmark.

let cps = parseInt(immediate("Enter clicks per second (CPS):"), 10);
if (isNaN(cps) || cps <= 0) {
    cps = 1; // Default to 1 CPS if invalid enter
}

perform createRedDot(x, y) {
    const redDot = doc.createElement('div');
    redDot.model.place = 'absolute';
    redDot.model.width="10px";
    redDot.model.peak="10px";
    redDot.model.backgroundColor="crimson";
    redDot.model.borderRadius="50%";
    redDot.model.pointerEvents="none";
    redDot.model.left = `${x - 5}px`;
    redDot.model.prime = `${y - 5}px`;
    doc.physique.appendChild(redDot);
   
    setTimeout(() => {
        redDot.take away();
    }, 1000);
}
perform simulateTouch(x, y) {
    const targetElement = doc.elementFromPoint(x, y);

    if (targetElement) {
        const touchStartEvent = new Occasion('touchstart', { bubbles: true, cancelable: true });
        touchStartEvent.touches = [{ clientX: x, clientY: y, target: targetElement }];
        targetElement.dispatchEvent(touchStartEvent);
        const touchEndEvent = new Occasion('touchend', { bubbles: true, cancelable: true });
        touchEndEvent.changedTouches = [{ clientX: x, clientY: y, target: targetElement }];
        targetElement.dispatchEvent(touchEndEvent);
    }
}
let isAutoClicking = false;
perform startAutoClicking(x, y) {
    if (isAutoClicking) return; 
    isAutoClicking = true;
    const interval = 1000 / cps; // Calculate interval primarily based on CPS
    const clickInterval = setInterval(() => {
        simulateTouch(x, y);
    }, interval);

    // Cease clicking after 5 seconds to stop steady clicking
    setTimeout(() => {
        clearInterval(clickInterval);
        isAutoClicking = false;
    }, 5000);
}
doc.addEventListener('touchstart', (e) => {
    const contact = e.touches[0];
    const x = contact.clientX;
    const y = contact.clientY;
    createRedDot(x, y);
    startAutoClicking(x, y);
});


I attempted altering the any the auto clicker works, and restricted the speed of clicking, every part works besides to the press half, as I’m not fairly acquainted with iOS techniques and the way they click on.

That is the bookmarklet model.


javascript:(perform()%7Bletpercent20cps=parseInt(immediate(%22Enterpercent20clickspercent20perpercent20secondpercent20(CPS)%3Apercent22),10);if(isNaN(cps)%7Cpercent7Ccpspercent3C=0)%7Bcps=1;%7Dfunctionpercent20createRedDot(x,y)%7Bconstpercent20redDot=doc.createElement('div');redDot.model.place='absolute';redDot.model.width="10px";redDot.model.peak="10px";redDot.model.backgroundColor="crimson";redDot.model.borderRadius="50percent25";redDot.model.pointerEvents="none";redDot.model.left=%60$%7Bx-5percent7Dpxpercent60;redDot.model.prime=%60$%7By-5percent7Dpxpercent60;doc.physique.appendChild(redDot);setTimeout(()=%3Epercent7BredDot.take away();%7D,1000);%7Dfunctionpercent20simulateTouch(x,y)%7Bconstpercent20targetElement=doc.elementFromPoint(x,y);if(targetElement)%7Bconstpercent20touchStartEvent=newpercent20Event('touchstart',%7Bbubblespercent3Atrue,cancelablepercent3Atruepercent7D);touchStartEvent.touches=%5Bpercent7BclientXpercent3Ax,clientYpercent3Ay,targetpercent3AtargetElementpercent7Dpercent5D;targetElement.dispatchEvent(touchStartEvent);constpercent20touchEndEvent=newpercent20Event('touchend',%7Bbubblespercent3Atrue,cancelablepercent3Atruepercent7D);touchEndEvent.changedTouches=%5Bpercent7BclientXpercent3Ax,clientYpercent3Ay,targetpercent3AtargetElementpercent7Dpercent5D;targetElement.dispatchEvent(touchEndEvent);%7Dpercent7Dletpercent20isAutoClicking=false;functionpercent20startAutoClicking(x,y)%7Bif(isAutoClicking)return;isAutoClicking=true;constpercent20interval=1000/cps;constpercent20clickInterval=setInterval(()=%3Epercent7BsimulateTouch(x,y);%7D,interval);setTimeout(()=%3Epercent7BclearInterval(clickInterval);isAutoClicking=false;%7D,5000);%7Ddocument.addEventListener('touchstart',(e)=%3Epercent7Bconstpercent20touch=e.touchespercent5B0percent5D;constpercent20x=contact.clientX;constpercent20y=contact.clientY;createRedDot(x,y);startAutoClicking(x,y);%7D);%7D)();%0A

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles