Skip to content

Instantly share code, notes, and snippets.

@zbinlin
Last active July 4, 2021 06:54
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save zbinlin/d0cda26ec6cdcacfec8bafdc0614d0d3 to your computer and use it in GitHub Desktop.
Save zbinlin/d0cda26ec6cdcacfec8bafdc0614d0d3 to your computer and use it in GitHub Desktop.
/**
* For Google Voice
* @Author zbinlin <zbinlin@outlook.com>
*/
var sleep = delay => new Promise(resolve => setTimeout(resolve, delay));
var composeClick = function x(btn) {
var rect = btn.getBoundingClientRect();
var x = Math.floor(rect.clientX + rect.width * Math.random());
var y = Math.floor(rect.clientY + rect.height * Math.random());
var screenX = Math.floor(x + window.screen.availLeft);
var screenY = Math.floor(y + window.screen.availTop);
const mousedown = new MouseEvent("mousedown", {
screenX: screenX,
screenY: screenY,
clientX: x,
clientY: y,
});
const click = new MouseEvent("click", {
screenX: screenX,
screenY: screenY,
clientX: x,
clientY: y,
});
const mouseup = new MouseEvent("mouseup", {
screenX: screenX,
screenY: screenY,
clientX: x,
clientY: y,
});
btn.dispatchEvent(mousedown);
return sleep(150 + Math.random() * 30)
.then(() => {
btn.dispatchEvent(click);
return sleep(30 + Math.random() * 30);
}).then(() => {
btn.dispatchEvent(mouseup);
});
}
function task() {
var btn = document.querySelector(".continueButton");
if (!btn) {
alert("Finish");
return;
}
composeClick(btn)
.then(() => {
// 在此调整点击时间间隔
return sleep(500 + Math.random() * 3000);
})
.then(() => {
task();
});
}
task();
@sdjk
Copy link

sdjk commented Mar 28, 2017

Uncaught TypeError: Failed to construct 'MouseEvent': The provided double value is non-finite.
at x (:11:21)
at task (:45:3)
at :54:1

@LuvLetter
Copy link

Safari: OK
Chrome: Failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment