Last active
March 10, 2020 12:07
-
-
Save hisivasankar/7ab032fab464bd182ee4fd07ebe740dd to your computer and use it in GitHub Desktop.
Playing Google Holi 2020 - Automation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simulate click behaviour based on x, y coordinates | |
function click(x, y) { | |
let elm = document.querySelector("canvas.ZRgdub"); | |
let ev = document.createEvent("MouseEvents"); | |
ev.initMouseEvent( "click", true, true, window, | |
0, 0, 0, x, y, | |
false, false, false, false, | |
0, null | |
); | |
elm.dispatchEvent(ev); | |
} | |
/** | |
* Building screen x, y where click will be triggered | |
*/ | |
function buildCoords() { | |
let points = [] | |
for(let y = 25; y < window.outerHeight; y+=90) { | |
for(let x = 25; x < window.outerWidth; x+=90) { | |
points.push({x, y}); | |
} | |
} | |
return points; | |
} | |
let timer = null; | |
let happyHoli = function(delay) { | |
let interval = delay || 100; | |
coords = buildCoords(); | |
// Ready, set, go - Happy Holi!!!! | |
document.querySelector("canvas.hide-focus-ring").click() | |
// Triggers click every 100 ms by default if delay is not provided | |
timer = setInterval(() => { | |
if(coords.length === 0) { | |
clearInterval(timer); | |
console.log("Timer Cleared"); | |
return; | |
} | |
const coord = coords.shift(); | |
console.log("Painting: ", coord); | |
click(coord.x, coord.y) | |
}, interval); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy-paste the above in developer tools console and then execute
happyHoli(<seconds>)
For example,
happyHoli(50);