Skip to content

Instantly share code, notes, and snippets.

@anjianshi
Last active August 29, 2015 14:05
Show Gist options
  • Save anjianshi/7f8f3ffc1d38279bccc7 to your computer and use it in GitHub Desktop.
Save anjianshi/7f8f3ffc1d38279bccc7 to your computer and use it in GitHub Desktop.
function normal() {
var color1, color1box, color2, color2box;
var boxes = document.querySelectorAll('#box > span'), boxLen = boxes.length;
for(var i = 0; i < boxLen; i++) {
var box = boxes[i], color = box.style.backgroundColor;
if(i == 0) {
color1 = color;
color1box = box;
} else if(!color2) {
if(color != color1) {
if(i > 1) {
box.click();
setTimeout(normal);
return;
} else {
color2 = color;
color2box = box;
}
}
} else {
(color == color1 ? color2box : color1box).click();
setTimeout(normal);
return;
}
}
}
function start() {
document.getElementById('box').style.display = 'none';
normal();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment