Skip to content

Instantly share code, notes, and snippets.

@nitobuendia
Created May 24, 2019 09:01
Show Gist options
  • Save nitobuendia/20264fd1375fb9465d420fede4281bb1 to your computer and use it in GitHub Desktop.
Save nitobuendia/20264fd1375fb9465d420fede4281bb1 to your computer and use it in GitHub Desktop.
Colors of the Wind - Kube-Kube AutoWin
/**
* Clicks the different colored tile.
* Wins the game on https://kuku-kube.com/
* To use, simply start the game and paste this code on
* the JavaScript console.
*/
const clickBoxColor = () => {
let lastColor;
const boxes = document.querySelectorAll('#box span');
for (let i = 0; i < boxes.length; i++) {
const box = boxes[i];
const bgColor = box.style.backgroundColor;
if (!lastColor) {
lastColor = bgColor;
continue;
}
if (lastColor === bgColor) {
continue;
} else {
// Current and last color are different.
if (i > 1) {
// If it is not the second element, at least two were the same color.
// Hence, it is safe to click this one.
box.click();
} else {
// If it is the second element, we need to check a third color to
// decide which one is the different one.
const nextBox = boxes[2];
const nextBoxBgColor = nextBox.style.backgroundColor;
if (lastColor === nextBoxBgColor) {
boxes[1].click();
} else {
boxes[0].click();
}
}
}
}
};
// Clicks every 250 miliseconds.
// Change to increase or decrease frequency.
setInterval(clickBoxColor, 250);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment