Last active
August 29, 2015 14:22
-
-
Save lucasconstantino/4508bd21e7c59a55807a to your computer and use it in GitHub Desktop.
Automated script to play http://kolor.moro.es/
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
/** | |
* Jus' encapsulating to avoid pluting global scope. | |
*/ | |
(function () { | |
var kolorContainer = document.querySelector('#kolor-kolor') | |
, buttons = document.querySelectorAll('#kolor-start, #kolor-restart') | |
, endBlock = document.querySelector('#kolor-end-block') | |
, interval; | |
// NodeList does not implement array methods :( | |
[].forEach.call(buttons, function (button) { | |
button.innerHTML += ' (cheating)'; | |
button.addEventListener('click', startRobot); | |
}); | |
/** | |
* Find a color match and select it. | |
*/ | |
function findAndSelect() { | |
var currentColor = kolorContainer.style.backgroundColor; | |
[].some.call(document.querySelectorAll('#kolor-options li a'), function (a) { | |
return a.style.backgroundColor == currentColor ? a.click() & true : false; | |
}); | |
} | |
/** | |
* Start the robot. | |
*/ | |
function startRobot() { | |
interval = setInterval(iterate, 50); | |
} | |
/** | |
* Loop iteration. | |
*/ | |
function iterate() { | |
endBlock.style.display != 'none' ? findAndSelect() : clearInterval(interval); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment