Created
October 3, 2014 09:04
-
-
Save priithaamer/2ba52969bad4cd8013cd to your computer and use it in GitHub Desktop.
Plays http://game.ioxapp.com/color for you
This file contains hidden or 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
var play = function() { | |
var boxes = $('#box span'); | |
var colors = boxes.map(function(idx, item) { | |
return $(item).css('background-color'); | |
}); | |
var color1 = {color: $.unique(colors)[0], count: 0}; | |
var color2 = {color: $.unique(colors)[1], count: 0}; | |
boxes.each(function(idx, item) { | |
if ($(item).css('background-color') == color1.color) { | |
color1.count++; | |
} else { | |
color2.count++; | |
} | |
}); | |
if (color1.count < color2.count) { | |
$('#box span[style*="' + color1.color + '"]').eq(0).click(); | |
} else { | |
$('#box span[style*="' + color2.color + '"]').eq(0).click(); | |
} | |
setTimeout(play, 1); | |
} |
Breaking the each loop in the right moment improves even more with:
if (color1.color && color2.color && (color1.count > 1 || color2.count > 1)) {
return false;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minor speed improvement: