Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const autoCollector = {
- units: [
- {'spear': 700},
- {'sword': 379},
- {'axe': 0},
- {'archer': 0},
- {'light': 0},
- {'marcher': 0},
- {'heavy': 0},
- {'knight': 1}
- ],
- intervalId: 0,
- times: 0,
- percents: [0.576923077, 0.230769231, 0.115384615, 0.0769230769],
- options: document.getElementsByClassName("options-container")[0].children,
- setUnitAmount(name, amount) {
- const element = document.getElementsByName(name)[0];
- element.value = amount;
- element.dispatchEvent(new Event('change'));
- },
- unitAvailable: function (name) {
- const field = document.getElementsByName(name)[0];
- const text = field.parentNode.lastChild.innerHTML;
- return +(text.substr(1, text.length - 2));
- },
- calculateAndSetUnits: function (level) {
- const percent = this.percents[level];
- for (let i = 0; i < this.units.length; i++) {
- const current = this.units[i];
- const name = Object.keys(current);
- const amount = Math.floor(current[name] * percent);
- const available = this.unitAvailable(name);
- this.setUnitAmount(name, Math.min(amount, available));
- }
- },
- tick: function () {
- for (let i = 0; i < this.options.length; i++) {
- const element = this.options[i].lastChild.lastChild;
- if (element.classList.contains("inactive-view")) {
- if (element.firstChild === null)
- continue;
- this.calculateAndSetUnits(i);
- element.lastChild.firstChild.click();
- this.times++;
- if(this.times === 20)
- location.reload();
- break;
- }
- }
- },
- start: function () {
- if (this.intervalId !== 0)
- throw new Error("Already started!");
- else
- this.intervalId = setInterval(() => this.tick(), 10000)
- },
- stop: function () {
- if (this.intervalId === 0)
- throw new Error("Not started yet!");
- else {
- clearInterval(this.intervalId);
- this.intervalId = 0;
- }
- }
- };
- autoCollector.start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement