SHARE
TWEET

Untitled

a guest Jan 20th, 2020 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var collector = {
  2.     units: [
  3.         {'spear': 520},
  4.         {'sword': 0},
  5.         {'axe': 0},
  6.         {'archer': 0},
  7.         {'light': 0},
  8.         {'marcher': 0},
  9.         {'heavy': 0},
  10.         {'knight': 0}
  11.     ],
  12.     times: 0,
  13.     percents: [0.576923077, 0.230769231, 0.115384615, 0.0769230769],
  14.     options: document.getElementsByClassName("options-container")[0].children,
  15.     setUnitAmount(name, amount) {
  16.         const element = document.getElementsByName(name)[0];
  17.  
  18.         if (element === undefined)
  19.             return;
  20.  
  21.         element.value = amount;
  22.         element.dispatchEvent(new Event('change'));
  23.     },
  24.     unitAvailable: function (name) {
  25.         const field = document.getElementsByName(name)[0];
  26.         if (field === undefined)
  27.             return 0;
  28.         const text = field.parentNode.lastChild.innerHTML;
  29.         return +(text.substr(1, text.length - 2));
  30.     },
  31.     calculateAndSetUnits: function (level) {
  32.         const percent = this.percents[level];
  33.  
  34.         for (let i = 0; i < this.units.length; i++) {
  35.             const current = this.units[i];
  36.  
  37.             const name = Object.keys(current);
  38.             const amount = Math.floor(current[name] * percent);
  39.             const available = this.unitAvailable(name);
  40.  
  41.             this.setUnitAmount(name, Math.min(amount, available));
  42.         }
  43.     },
  44.     select: function () {
  45.         for (let i = 0; i < this.options.length; i++) {
  46.             const element = this.options[i].lastChild.lastChild;
  47.  
  48.             if (element.classList.contains("inactive-view")) {
  49.  
  50.                 if (element.firstChild === null)
  51.                     continue;
  52.  
  53.                 this.calculateAndSetUnits(i);
  54.                 element.lastChild.firstChild.click();
  55.                 break;
  56.             }
  57.         }
  58.     }
  59. };
  60.  
  61. collector.select();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top