Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. /**
  2. * Jus' encapsulating to avoid pluting global scope.
  3. */
  4. (function () {
  5.  
  6. var kolorContainer = document.querySelector('#kolor-kolor')
  7. , buttons = document.querySelectorAll('#kolor-start, #kolor-restart')
  8. , endBlock = document.querySelector('#kolor-end-block')
  9. , interval;
  10.  
  11. // NodeList does not implement array methods :(
  12. [].forEach.call(buttons, function (button) {
  13. button.innerHTML += ' (cheating)';
  14. button.addEventListener('click', startRobot);
  15. });
  16.  
  17. /**
  18. * Find a color match and select it.
  19. */
  20. function findAndSelect() {
  21. var currentColor = kolorContainer.style.backgroundColor;
  22. [].some.call(document.querySelectorAll('#kolor-options li a'), function (a) {
  23. return a.style.backgroundColor == currentColor ? a.click() & true : false;
  24. });
  25. }
  26.  
  27. /**
  28. * Start the robot.
  29. */
  30. function startRobot() {
  31. interval = setInterval(iterate, 50);
  32. }
  33.  
  34. /**
  35. * Loop iteration.
  36. */
  37. function iterate() {
  38. endBlock.style.display != 'none' ? findAndSelect() : clearInterval(interval);
  39. }
  40. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement