Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement