Skip to content

Instantly share code, notes, and snippets.

@lucasconstantino
Last active August 29, 2015 14:22
Show Gist options
  • Save lucasconstantino/4508bd21e7c59a55807a to your computer and use it in GitHub Desktop.
Save lucasconstantino/4508bd21e7c59a55807a to your computer and use it in GitHub Desktop.
Automated script to play http://kolor.moro.es/
/**
* 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