Skip to content

Instantly share code, notes, and snippets.

@adregan
Last active August 29, 2015 14:07
Show Gist options
  • Save adregan/1c82efb1c427ecf3ab7e to your computer and use it in GitHub Desktop.
Save adregan/1c82efb1c427ecf3ab7e to your computer and use it in GitHub Desktop.
// stashes the box
var box = document.getElementById('box');
// Sets a 1 ms interval to call clickThemAll()
setInterval(clickThemAll, 1);
// Clicks the play button to start the game
document.querySelector('.play-btn').click();
function clickThemAll(){
//grabs the children, sets prevBG to false, stores length
var children = box.querySelectorAll('span')
, prevBG = false
, len = children.length
;
for (i = 0; i < len; ++i) {
// grabs the background
var background = children[i].style.background;
// checks if the background is different than the previous. If so, clicks.
if (prevBG && prevBG !== background) {
children[i].click();
}
// If none of them are different than the first one is the square to click
else if (i === (len - 1)) {
children[0].click();
}
// set the prevBG to the current background
prevBG = background;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment