Last active
August 29, 2015 14:07
-
-
Save lucasmotta/bffd350c6dd6b0f9d63d to your computer and use it in GitHub Desktop.
Beating http://game.ioxapp.com/color/
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
/** | |
The following script works like this: | |
1. Auto play the game | |
2. Get all the color elements (<span>) inside the game | |
3. Push the elements to different arrays based on it's color | |
i.e: | |
– If it's a "red" color, goes to the "red" array | |
– If it's a "blue" color, goes to the "blue" array | |
4. Check each of those arrays has only one element, which is the one that | |
has a different/unique color compared to the others | |
5. Force a click on this element to move on to the next level | |
6. Repeat. | |
*/ | |
// Create a new instance of the click event | |
var clickEvent = new MouseEvent('click', { 'bubbles': true }); | |
// Select the play-button and dispatch the click event to start the game | |
document.querySelector(".play-btn").dispatchEvent(clickEvent); | |
// Create a interval to run this script | |
setInterval(function () { | |
// object to store our colors | |
var colors = {}; | |
// select all the <span> elements inside the #box | |
// we are using the $$, it works only on Chrome and Firefox: | |
// https://developer.chrome.com/devtools/docs/commandline-api#selector_1 | |
var nodes = $$("#box span"); | |
var color, i; | |
// Create a loop through our nodes | |
for (i = 0; node = nodes[i++];) { | |
// Get the background color of the <span> element | |
color = node.style.background; | |
// Create an empty array on our object using the color as the object key | |
// but only if it wasn't created yet | |
if (!colors[color]) { | |
colors[color] = []; | |
}; | |
// We add our <span> node to our just created array | |
colors[color].push(node); | |
}; | |
// Loop through our object and check if the length is only 1 | |
for (color in colors) { | |
// If it is, we stop the loop. We've found the unique color ;) | |
if (colors[color].length === 1) break; | |
} | |
// Force a click on our element | |
colors[color][0].dispatchEvent(clickEvent); | |
}, 1); |
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
// go to the website and run this on the console | |
ev=new MouseEvent('click',{'bubbles': true});document.querySelector(".play-btn").dispatchEvent(ev); | |
setInterval(function(){ for(i=0,cs={};A=$$("#box span")[i++];) {c=A.style.background;if(!cs[c]){cs[c]=[]};cs[c].push(A)}; | |
for(k in cs){ if(cs[k].length === 1) break; } | |
cs[k][0].dispatchEvent(ev);}, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment