script.jsexport async function mimicHoldDown(element, {button = 0, X, Y, shiftKey = false, ctrlKey = false, altKey = false, holding = 1000, wait = 10} = {}) {
const touch = new Touch({
identifier: 0,
target: element,
clientX: X,
clientY: Y,
pageX: X + window.scrollX,
pageY: Y + window.scrollY,
});
const mouseOptions = {
button: 0,
clientX: X,
clientY: Y,
changedTouches: [touch],
touches: [touch],
bubbles: true,
cancelable: true,
shiftKey: shiftKey,
ctrlKey: ctrlKey,
altKey: altKey,
view: window,
};
element.dispatchEvent(new TouchEvent("touchstart", mouseOptions));
element.dispatchEvent(new MouseEvent("mousedown", mouseOptions));
await sleep(holding);
element.dispatchEvent(new MouseEvent("mouseup", mouseOptions));
element.dispatchEvent(new TouchEvent("touchend", mouseOptions));
element.dispatchEvent(new MouseEvent("click", mouseOptions));
await sleep(wait); // 少し待つ
}