Skip to content

Instantly share code, notes, and snippets.

@pulges
Forked from priithaamer/gist:2ba52969bad4cd8013cd
Last active August 29, 2015 14:07
Show Gist options
  • Save pulges/d6f6784479189878a0d0 to your computer and use it in GitHub Desktop.
Save pulges/d6f6784479189878a0d0 to your computer and use it in GitHub Desktop.
$('#box').css('display', 'none');
var play = function() {
var boxes = $('#box span'),
color1 = {count: 0},
color2 = {count: 0},
lastColor1Item, lastColor2Item;
boxes.each(function(idx, item) {
var color = $(item).css('background-color');
if (!color1.color) {
color1.color = color;
}
if (color == color1.color) {
color1.count++;
lastColor1Item = item;
} else {
if (!color2.color) {
color2.color = color;
}
color2.count++;
lastColor2Item = item;
}
if (color1.color && color2.color && (color1.count > 1 || color2.count > 1)) {
return false;
}
});
if (color1.count < color2.count) {
$(lastColor1Item).click();
} else {
$(lastColor2Item).click();
}
setTimeout(play, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment