Grepolisbot

Skrašlenie dizajnu tejto peknej prehliadačovej hry

  1. "use strict";
  2. class CultureUI {
  3. constructor(mainDiv) {
  4. this.mainDiv = mainDiv;
  5. }
  6.  
  7. createHeading() {
  8. const heading = document.createElement("h3");
  9. heading.textContent = "AutoCulture";
  10. heading.style.color = "Yellow";
  11. return heading;
  12. }
  13.  
  14. createDropDown(optionValues, name) {
  15. const dropDown = document.createElement("select");
  16. dropDown.setAttribute("name", name);
  17.  
  18. for (let i = 0; i < optionValues.length; i++) {
  19. const option = document.createElement("option");
  20. option.text = optionValues[i];
  21. dropDown.appendChild(option);
  22. }
  23.  
  24. return dropDown;
  25. }
  26.  
  27. createButton() {
  28. const button = document.createElement("button");
  29. button.textContent = "Start";
  30.  
  31. button.addEventListener("click", function () {
  32. let ac = new AutoCulture();
  33. const dropDown = document.querySelector(
  34. "select[name='culture-drop-down']"
  35. );
  36. const optDropDown = document.querySelector(
  37. "select[name='option-drop-down']"
  38. );
  39. const selectedValue = dropDown.value;
  40. const selectedOption = optDropDown.value;
  41. console.log(selectedOption);
  42. ac.run(selectedOption, selectedValue);
  43. });
  44.  
  45. return button;
  46. }
  47.  
  48. createAutoCultureDiv(name) {
  49. const autoFarmDiv = document.createElement("div");
  50. autoFarmDiv.className = name;
  51. return autoFarmDiv;
  52. }
  53.  
  54. createCultureUI() {
  55. const optionValues = [
  56. "Mestský festival",
  57. "Olympijské hry",
  58. "Víťazná procesia",
  59. "Divadelné hry",
  60. ];
  61.  
  62. const optionValues1 = [
  63. "02:00:00",
  64. "04:00:00",
  65. "08:00:00",
  66. "10:00:00",
  67. "11:00:00",
  68. "12:00:00",
  69. ];
  70.  
  71. const heading = this.createHeading();
  72. const dropDown = this.createDropDown(optionValues, "option-drop-down");
  73. const dropDown1 = this.createDropDown(optionValues1, "culture-drop-down");
  74. const button = this.createButton();
  75. const autoCultureDiv = this.createAutoCultureDiv("auto-culture-options");
  76. const autoCultureDiv1 = this.createAutoCultureDiv("auto-culture-timer");
  77.  
  78. autoCultureDiv.appendChild(dropDown);
  79.  
  80. autoCultureDiv1.appendChild(dropDown1);
  81. autoCultureDiv1.appendChild(button);
  82.  
  83. this.mainDiv.appendChild(heading);
  84. this.mainDiv.appendChild(autoCultureDiv);
  85. this.mainDiv.appendChild(autoCultureDiv1);
  86. }
  87. }
  88.  
  89. "use strict";
  90. class FarmUI {
  91. constructor(mainDiv) {
  92. this.mainDiv = mainDiv;
  93. }
  94.  
  95. createHeading() {
  96. const heading = document.createElement("h3");
  97. heading.textContent = "AutoFarm";
  98. heading.style.color = "green";
  99. return heading;
  100. }
  101.  
  102. createDropDown() {
  103. const dropDown = document.createElement("select");
  104. dropDown.setAttribute("name", "farm-drop-down");
  105.  
  106. const optionValues = [
  107. "00:05:00",
  108. "00:10:00",
  109. "00:20:00",
  110. "00:40:00",
  111. "01:30:00",
  112. "03:00:00",
  113. "04:00:00",
  114. "08:00:00",
  115. ];
  116.  
  117. for (let i = 0; i < optionValues.length; i++) {
  118. const option = document.createElement("option");
  119. option.text = optionValues[i];
  120. dropDown.appendChild(option);
  121. }
  122.  
  123. return dropDown;
  124. }
  125.  
  126. createButton() {
  127. const button = document.createElement("button");
  128. button.textContent = "Start";
  129.  
  130. button.addEventListener("click", function () {
  131. let af = new AutoFarm();
  132. const dropDown = document.querySelector("select[name='farm-drop-down']");
  133. const selectedValue = dropDown.value;
  134. af.run(selectedValue);
  135. });
  136.  
  137. return button;
  138. }
  139.  
  140. createAutoFarmDiv() {
  141. const autoFarmDiv = document.createElement("div");
  142. autoFarmDiv.className = "auto-farm";
  143. return autoFarmDiv;
  144. }
  145.  
  146. createFarmUI() {
  147. const heading = this.createHeading();
  148. const dropDown = this.createDropDown();
  149. const button = this.createButton();
  150. const autoFarmDiv = this.createAutoFarmDiv();
  151.  
  152. autoFarmDiv.appendChild(dropDown);
  153. autoFarmDiv.appendChild(button);
  154.  
  155. this.mainDiv.appendChild(heading);
  156. this.mainDiv.appendChild(autoFarmDiv);
  157. }
  158. }
  159.  
  160. "use strict";
  161.  
  162. class MainUI {
  163. constructor() {
  164. this.panel = document.getElementsByClassName(
  165. "ui_construction_queue instant_buy"
  166. )[0];
  167. this.createMainDiv();
  168. this.addDragFunctionality();
  169. this.createAutoFarmUI();
  170. }
  171.  
  172. createMainDiv() {
  173. this.mainDiv = document.createElement("div");
  174. this.mainDiv.setAttribute("name", "bot-main-div");
  175. this.mainDiv.style.position = "absolute";
  176. this.mainDiv.style.left = "0px";
  177. this.mainDiv.style.top = "0px";
  178. this.mainDiv.style.width = "300px";
  179. this.mainDiv.style.height = "500px";
  180. this.mainDiv.style.backgroundColor = "rgba(0, 0, 10, 0.5)";
  181. this.mainDiv.style.zIndex = "1000";
  182. this.mainDiv.style.borderRadius = "10px";
  183. let parentDiv = this.panel.parentNode;
  184. parentDiv.insertBefore(this.mainDiv, this.panel);
  185. }
  186.  
  187. addDragFunctionality() {
  188. let isDragging = false;
  189. let dragOffsetX = 0;
  190. let dragOffsetY = 0;
  191.  
  192. const startDrag = (event) => {
  193. isDragging = true;
  194. dragOffsetX = event.clientX - this.mainDiv.offsetLeft;
  195. dragOffsetY = event.clientY - this.mainDiv.offsetTop;
  196. };
  197.  
  198. const endDrag = () => {
  199. isDragging = false;
  200. };
  201.  
  202. const drag = (event) => {
  203. if (isDragging) {
  204. this.mainDiv.style.left = event.clientX - dragOffsetX + "px";
  205. this.mainDiv.style.top = event.clientY - dragOffsetY + "px";
  206. }
  207. };
  208.  
  209. this.mainDiv.addEventListener("mousedown", startDrag);
  210. this.mainDiv.addEventListener("mouseup", endDrag);
  211. this.mainDiv.addEventListener("mousemove", drag);
  212. }
  213.  
  214. createAutoFarmUI() {
  215. let farm = new FarmUI(this.mainDiv);
  216. farm.createFarmUI();
  217. let culture = new CultureUI(this.mainDiv);
  218. culture.createCultureUI();
  219. }
  220. }
  221.  
  222. "use strict";
  223.  
  224. class AutoFarm {
  225. constructor() {
  226. this.utils = new Utils();
  227. }
  228.  
  229. async selectVillages() {
  230. const linkElement = document.querySelector(
  231. "#overviews_link_hover_menu > div.box.middle.left > div > div > ul > li.subsection.captain.enabled > ul > li.farm_town_overview > a"
  232. );
  233.  
  234. function triggerClickEvent(target) {
  235. const clickEvent = new MouseEvent("click", {
  236. view: window,
  237. bubbles: true,
  238. cancelable: true,
  239. });
  240. target.dispatchEvent(clickEvent);
  241. }
  242.  
  243. triggerClickEvent(linkElement);
  244. await this.utils.timeout(889 + this.utils.generateDelay());
  245. }
  246.  
  247. async selectAll() {
  248. this.utils.waitForElementToAppear(
  249. "#fto_town_wrapper > div > div.game_header.bold > span.checkbox_wrapper > a",
  250. (element) => {
  251. element.click();
  252. }
  253. );
  254. await this.utils.timeout(798 + this.utils.generateDelay());
  255. }
  256.  
  257. async checkTime(seconds) {
  258. if (
  259. seconds === 300 ||
  260. seconds === 1200 ||
  261. seconds === 5400 ||
  262. seconds === 14400
  263. ) {
  264. this.utils.waitForElementToAppear(
  265. "#time_options_wrapper > div.time_options_default > div.fto_time_checkbox.fto_" +
  266. seconds +
  267. "> a",
  268. (element) => {
  269. element.click();
  270. }
  271. );
  272. } else {
  273. this.utils.waitForElementToAppear(
  274. "#time_options_wrapper > div.time_options_loyalty > div.fto_time_checkbox.fto_" +
  275. seconds +
  276. " > a",
  277. (element) => {
  278. element.click();
  279. }
  280. );
  281. }
  282. await this.utils.timeout(805 + this.utils.generateDelay());
  283. }
  284.  
  285. async collect() {
  286. this.utils.waitForElementToAppear(
  287. "#fto_claim_button > div.caption.js-caption",
  288. (element) => {
  289. element.click();
  290. }
  291. );
  292. await this.utils.timeout(985);
  293. }
  294.  
  295. async confirm() {
  296. this.utils.waitForElementToAppear(
  297. ".window_content.js-window-content > div > div.buttons > div.btn_confirm.button_new > div.caption.js-caption",
  298. (element) => {
  299. element.click();
  300. }
  301. );
  302. await this.utils.timeout(1188 + this.utils.generateDelay());
  303. }
  304.  
  305. async close() {
  306. this.utils.waitForElementToAppear(
  307. "body > div.ui-dialog.ui-corner-all.ui-widget.ui-widget-content.ui-front.ui-draggable.js-window-main-container > div.ui-dialog-titlebar.ui-corner-all.ui-widget-header.ui-helper-clearfix.ui-draggable-handle > button",
  308. (element) => {
  309. element.click();
  310. }
  311. );
  312. await this.utils.timeout(1205 + this.utils.generateDelay());
  313. }
  314.  
  315. async repeatFarm() {
  316. await this.selectVillages();
  317. await this.selectAll();
  318. await this.checkTime(this.seconds);
  319. await this.collect();
  320. await this.confirm();
  321. await this.close();
  322. console.log("Collecting is finished");
  323. }
  324.  
  325. async run(time) {
  326. console.log(time);
  327. const seconds = this.utils.convertToSeconds(time);
  328. console.log(seconds);
  329. this.seconds = seconds;
  330.  
  331. while (true) {
  332. await this.repeatFarm();
  333.  
  334. let delay =
  335. this.seconds * 1000 + Math.floor(Math.random() * (30000 - 5000) + 5000);
  336. console.log(delay);
  337. await this.utils.timeout(delay);
  338. }
  339. //await this.repeatFarm();
  340.  
  341. //setInterval(this.myFunction, 1000);
  342. }
  343. }
  344.  
  345. "use strict";
  346.  
  347. class AutoCulture {
  348. constructor() {
  349. this.utils = new Utils();
  350. }
  351.  
  352. async selectOverview() {
  353. this.utils.waitForElementToAppear(
  354. "#overviews_link_hover_menu > div.box.middle.left > div > div > ul > li.subsection.curator.enabled > ul > li.culture_overview > a",
  355. (element) => {
  356. element.click();
  357. }
  358. );
  359. await this.utils.timeout(658 + this.utils.generateDelay());
  360. }
  361.  
  362. async confirm() {
  363. this.utils.waitForElementToAppear("#start_all_celebrations", (element) => {
  364. element.click();
  365. });
  366. await this.utils.timeout(1001 + this.utils.generateDelay());
  367. }
  368.  
  369. async close() {
  370. this.utils.waitForElementToAppear(
  371. "body > div.ui-dialog.ui-corner-all.ui-widget.ui-widget-content.ui-front.ui-draggable.js-window-main-container > div.ui-dialog-titlebar.ui-corner-all.ui-widget-header.ui-helper-clearfix.ui-draggable-handle > button",
  372. (element) => {
  373. element.click();
  374. }
  375. );
  376. await this.utils.timeout(1488 + this.utils.generateDelay());
  377. }
  378.  
  379. async selectOption(opt) {
  380. let num = 1;
  381. switch (opt) {
  382. case "Mestský festival":
  383. num = 1;
  384. break;
  385. case "Olympijské hry":
  386. num = 2;
  387. break;
  388. case "Víťazná procesia":
  389. num = 3;
  390. break;
  391. case "Divadelné hry":
  392. num = 4;
  393. break;
  394. }
  395.  
  396. this.utils.waitForElementToAppear(
  397. "#place_celebration_select",
  398. (element) => {
  399. element.click();
  400. }
  401. );
  402. await this.utils.timeout(1488 + this.utils.generateDelay());
  403.  
  404. this.utils.waitForElementToAppear(
  405. "#place_celebration_select_list > div > div:nth-child(" + num + ")",
  406. (element) => {
  407. element.click();
  408. }
  409. );
  410. await this.utils.timeout(1488 + this.utils.generateDelay());
  411. }
  412.  
  413. async repeatCulture(opt) {
  414. await this.selectOverview();
  415. await this.selectOption(opt);
  416. await this.confirm();
  417. await this.close();
  418. console.log("Culture is being runned.");
  419. }
  420.  
  421. async run(opt, time) {
  422. console.log(time);
  423. const seconds = this.utils.convertToSeconds(time);
  424. console.log(seconds);
  425. this.seconds = seconds;
  426.  
  427. await this.repeatCulture(opt);
  428.  
  429. let delay =
  430. this.seconds * 1000 +
  431. Math.floor(Math.random() * (900000 - 180000) + 120000);
  432. console.log(delay);
  433. }
  434. }
  435.  
  436. "use strict";
  437.  
  438. class Utils {
  439. timeout(delay) {
  440. return new Promise((r) => setTimeout(r, delay));
  441. }
  442.  
  443. generateDelay() {
  444. return Math.floor(Math.random() * (601 - 300) + 300);
  445. }
  446.  
  447. convertToSeconds(timeString) {
  448. const [hours, minutes, seconds] = timeString.split(":");
  449. const totalSeconds =
  450. parseInt(hours) * 3600 + parseInt(minutes) * 60 + parseInt(seconds);
  451. return totalSeconds;
  452. }
  453.  
  454. waitForElementToAppear(selector, callback, interval = 100, maxAttempts = 10) {
  455. var attempts = 0;
  456. var timer = setInterval(function () {
  457. attempts++;
  458. var element = document.querySelector(selector);
  459. if (element || attempts >= maxAttempts) {
  460. clearInterval(timer);
  461. if (element) {
  462. callback(element);
  463. } else {
  464. console.log("Element not found within the specified time.");
  465. }
  466. }
  467. }, interval);
  468. }
  469. }
  470.  
  471. "use strict";
  472.  
  473. (function () {
  474. window.addEventListener("load", function () {
  475. setTimeout(function () {
  476. new MainUI();
  477. }, 2000); // 2000 milliseconds = 2 seconds delay
  478. });
  479. })();
  480.  
  481. // ==UserScript==
  482. // @name Grepolisbot
  483. // @namespace http://tampermonkey.net/
  484. // @version 0.2
  485. // @description Skrašlenie dizajnu tejto peknej prehliadačovej hry
  486. // @author You
  487. // @match https://*.grepolis.com/game/*
  488. // @icon https://www.google.com/s2/favicons?sz=64&domain=grepolis.com
  489. // @grant none
  490. // @license MIT
  491. // ==/UserScript==