Romusha

try to build the world!

  1. // ==UserScript==
  2. // @name Romusha
  3. // @namespace erepfarm
  4. // @version 2024-05-14
  5. // @description try to build the world!
  6. // @author Prince of Spade
  7. // @match https://www.erepublik.com/es/economy/myCompanies
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=erepublik.com
  9. // @grant none
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13.  
  14. window.addEventListener('load', mainFunction);
  15.  
  16. async function mainFunction() {
  17. const capthca = checkSessionValidationExists();
  18. if (!capthca) {
  19. const _token = csrfToken;
  20. let energy = erepublik.citizen.energy;
  21. const loops = Math.floor(energy / 100);
  22. createDivElement('energyloop', 'sidebar', 'LOOPS: ');
  23. displayValueInHtml('energyloop', loops);
  24. createDivElement('energyloop', 'sidebar', '=================');
  25. createDivElement('list', 'sidebar', '');
  26.  
  27. for (let i = 0; i < loops; i++) {
  28. const payload = payloadOT(_token);
  29. const ot = "https://www.erepublik.com/en/economy/workOvertime";
  30. await PostRequest(payload, ot);
  31. await delay(3000);
  32. displayValueInHtml('list', i);
  33. }
  34.  
  35. createDivElement('energyloop', 'sidebar', '== DONE ==');
  36. }
  37.  
  38.  
  39.  
  40. }
  41.  
  42. function checkSessionValidationExists() {
  43. if (typeof SERVER_DATA !== 'undefined' && SERVER_DATA.sessionValidation !== undefined) {
  44. return true;
  45. } else {
  46. return false;
  47. }
  48. }
  49.  
  50. // Function to construct the payload from variables
  51. function payloadOT(_token) {
  52. const action_type = "workOvertime";
  53.  
  54. return {
  55. action_type,
  56. _token
  57. };
  58. }
  59.  
  60. // Function to send the payload using POST request
  61. async function PostRequest(payload, url) {
  62.  
  63. try {
  64. const response = await fetch(url, {
  65. method: "POST",
  66. headers: {
  67. "Content-Type": "application/x-www-form-urlencoded"
  68. },
  69. body: Object.keys(payload)
  70. .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(payload[key])}`)
  71. .join('&')
  72. });
  73.  
  74. const responseData = await response.json();
  75. return responseData;
  76. } catch (error) {
  77. console.error("Error:", error);
  78. return null;
  79. }
  80. }
  81.  
  82. function delay(ms) {
  83. return new Promise(resolve => setTimeout(resolve, ms));
  84. }
  85.  
  86. function createDivElement(divId, parentId, textContent) {
  87. const parentElement = document.querySelector(`.${parentId}`);
  88. if (parentElement) {
  89. const newDiv = document.createElement('div');
  90. newDiv.id = divId;
  91. newDiv.textContent = textContent;
  92. parentElement.appendChild(newDiv);
  93. } else {
  94. console.error(`Parent element with class '${parentId}' not found.`);
  95. }
  96. }
  97.  
  98. // Function to display any value in HTML
  99. function displayValueInHtml(elementId, value) {
  100. const element = document.getElementById(elementId);
  101. if (element) {
  102. element.textContent = `${element.textContent} ${value}`;
  103. } else {
  104. console.error(`Element with ID '${elementId}' not found.`);
  105. }
  106. }
  107. })();