Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. const autoCollector = {
  2. units: [
  3. {'spear': 700},
  4. {'sword': 379},
  5. {'axe': 0},
  6. {'archer': 0},
  7. {'light': 0},
  8. {'marcher': 0},
  9. {'heavy': 0},
  10. {'knight': 1}
  11. ],
  12. intervalId: 0,
  13. times: 0,
  14. percents: [0.576923077, 0.230769231, 0.115384615, 0.0769230769],
  15. options: document.getElementsByClassName("options-container")[0].children,
  16. setUnitAmount(name, amount) {
  17. const element = document.getElementsByName(name)[0];
  18.  
  19. element.value = amount;
  20. element.dispatchEvent(new Event('change'));
  21. },
  22. unitAvailable: function (name) {
  23. const field = document.getElementsByName(name)[0];
  24. const text = field.parentNode.lastChild.innerHTML;
  25. return +(text.substr(1, text.length - 2));
  26. },
  27. calculateAndSetUnits: function (level) {
  28. const percent = this.percents[level];
  29.  
  30. for (let i = 0; i < this.units.length; i++) {
  31. const current = this.units[i];
  32.  
  33. const name = Object.keys(current);
  34. const amount = Math.floor(current[name] * percent);
  35. const available = this.unitAvailable(name);
  36.  
  37. this.setUnitAmount(name, Math.min(amount, available));
  38. }
  39. },
  40. tick: function () {
  41. for (let i = 0; i < this.options.length; i++) {
  42. const element = this.options[i].lastChild.lastChild;
  43.  
  44. if (element.classList.contains("inactive-view")) {
  45.  
  46. if (element.firstChild === null)
  47. continue;
  48.  
  49. this.calculateAndSetUnits(i);
  50. element.lastChild.firstChild.click();
  51. this.times++;
  52.  
  53. if(this.times === 20)
  54. location.reload();
  55.  
  56. break;
  57. }
  58. }
  59. },
  60. start: function () {
  61. if (this.intervalId !== 0)
  62. throw new Error("Already started!");
  63. else
  64. this.intervalId = setInterval(() => this.tick(), 10000)
  65. },
  66. stop: function () {
  67. if (this.intervalId === 0)
  68. throw new Error("Not started yet!");
  69. else {
  70. clearInterval(this.intervalId);
  71. this.intervalId = 0;
  72. }
  73. }
  74. };
  75.  
  76. autoCollector.start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement