Checking S0mething

Find S0mething in s0mewhere

  1. // ==UserScript==
  2. // @name Checking S0mething
  3. // @version 1.666.3
  4. // @description Find S0mething in s0mewhere
  5. // @author S0me1
  6. // @match https://www.erepublik.com/en
  7. // @grant GM_setValue
  8. // @grant GM_getValue
  9. // @grant GM_addStyle
  10. // @namespace https://greasyfork.org/users/1144622
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. // Declare variables
  15. var cid = erepublik.citizen.countryLocationId;
  16. var divi = 1;
  17. var countryList = [9, 42, 23, 14, 70, 39, 48, 49, 54, 56, 71, 72, 66, 57, 67, 35, 53, 81, 1, 68, 30, 40, 24, 79, 52]; // Define the countryList array
  18. var dataBattle = {}; // Change from [] to {}
  19. var idbattle = []; // New array to store battle IDs
  20. var dataDivision = {}; // New object to store relevant data from battles object
  21. var emptyBattle = []; // Array to store battle IDs with missing div data
  22. var citynameA = []; // Array to store city name
  23.  
  24. // Function to fetch data and process it
  25. async function fetchData(url) {
  26. const response = await fetch(url);
  27. return response.json();
  28. }
  29.  
  30. // Function to process data for a specific idbattle from dataBattle and dataDivision
  31. function processDataForId(battleId) {
  32. if (dataBattle.hasOwnProperty(battleId)) {
  33. // Get the data from dataBattle using the battleId as the index
  34. var zoneId = dataBattle[battleId].zone_id;
  35. var cityname = dataBattle[battleId].city.name;
  36.  
  37. if (dataDivision.hasOwnProperty(battleId)) {
  38. // Get the data from dataDivision using the battleId as the index
  39. var groundZoneId = dataDivision[battleId].groundZoneId;
  40. var aircraftZoneId = dataDivision[battleId].aircraftZoneId;
  41.  
  42. // Fetch JSON from "https://www.erepublik.com/en/military/battle-stats/" + battleId
  43. fetchData("https://www.erepublik.com/en/military/battle-stats/" + battleId)
  44. .then(data => {
  45. // Step 1: Check if zoneId exists in the fetched JSON data
  46. const finished = data.zone_finished;
  47. const zoneIdData = data.stats.current[zoneId];
  48.  
  49. // Step 2: Check if "divi" and "divi[cid][groundZoneId]" exist in the zoneIdData object
  50. if (zoneIdData && zoneIdData[divi] && zoneIdData[divi][cid] && zoneIdData[divi][cid][groundZoneId]) {
  51. // Further processing can be done here if "divi[cid][groundZoneId]" exists
  52. } else {
  53. if (finished == false) {
  54. emptyBattle.push("https://www.erepublik.com/en/military/battlefield/" + battleId + "/" + groundZoneId);
  55. citynameA.push(cityname + " - R" + zoneId);
  56. }
  57. }
  58. })
  59. .catch(error => {
  60. console.error("Error fetching JSON:", error);
  61. });
  62. }
  63. }
  64. }
  65.  
  66. // Function to display the results in the sidebar and open links in new tabs
  67. function displayResults() {
  68. var sidebarDiv = document.querySelector('.sidebar');
  69. var resultDiv = document.createElement('div');
  70. resultDiv.classList.add('results'); // Add a class for styling (optional)
  71.  
  72. for (var i = 0; i < emptyBattle.length; i++) {
  73. var battleURL = emptyBattle[i];
  74. var cityName = citynameA[i];
  75.  
  76. var anchorElement = document.createElement('a');
  77. anchorElement.href = battleURL;
  78. anchorElement.textContent = cityName;
  79. anchorElement.style.display = 'block'; // Add some spacing between links
  80.  
  81. resultDiv.appendChild(anchorElement);
  82.  
  83. // Open link in a new tab with a delay of 30 seconds
  84. setTimeout(function (url) {
  85. return function () {
  86. window.open(url, "_blank");
  87. };
  88. }(battleURL), 30000 * (i + 1)); // 30 seconds delay for each link
  89. }
  90.  
  91. // Remove any existing results
  92. var existingResults = document.querySelectorAll('.results');
  93. existingResults.forEach(result => {
  94. result.remove();
  95. });
  96.  
  97. // Append the new results div to the sidebar
  98. sidebarDiv.appendChild(resultDiv);
  99. }
  100.  
  101.  
  102. // Main function to execute the script
  103. async function main() {
  104. try {
  105. // Fetch the first JSON file and process it
  106. const firstData = await fetchData("https://www.erepublik.com/en/military/campaignsJson/list");
  107.  
  108. // Get battles object
  109. var battles = firstData.battles;
  110.  
  111. // Loop through each object inside the battles object
  112. for (var battleId in battles) {
  113. if (battles.hasOwnProperty(battleId)) {
  114. var battle = battles[battleId];
  115. var dw = battle.war_type;
  116.  
  117. if (dw == "direct"){
  118. // main if
  119. var inv = battle.inv.id;
  120. var def = battle.def.id;
  121. var inva = battle.inv.allies;
  122. var defa = battle.def.allies;
  123.  
  124. if (countryList.includes(inv) && countryList.includes(def)) {
  125. // Check if inv.id or def.id matches cid
  126. if (inv === cid || def === cid) {
  127. // Store the battle data in the dataBattle object using battle ID as the index
  128. dataBattle[battle.id] = battle;
  129.  
  130. // Push the battle ID to the idbattle array
  131. idbattle.push(battle.id);
  132. }
  133.  
  134. if (inva.includes(cid) || defa.includes(cid)){
  135. // Store the battle data in the dataBattle object using battle ID as the index
  136. dataBattle[battle.id] = battle;
  137.  
  138. // Push the battle ID to the idbattle array
  139. idbattle.push(battle.id);
  140. }
  141. }
  142. }
  143. }
  144. }
  145.  
  146. // Show dataBattle and idbattle in the console
  147. console.log("dataBattle:", dataBattle);
  148. console.log("idbattle:", idbattle);
  149.  
  150. // Fetch the second JSON file and process it manually
  151. const secondData = await fetchData("https://www.erepublik.com/en/military/campaignsJson/citizen");
  152.  
  153. // Get battles object from the second JSON file
  154. var battles2 = secondData.battles;
  155.  
  156. // Process data for each idbattle using the processDataForId function
  157. for (let i = 0; i < idbattle.length; i++) {
  158. let battleId = idbattle[i];
  159.  
  160. // Check if the battleId exists in the battles object from the second JSON file
  161. if (battles2.hasOwnProperty(battleId)) {
  162. // Store the relevant battle data in the dataDivision object using battle ID as the index
  163. dataDivision[battleId] = battles2[battleId];
  164. }
  165. }
  166.  
  167. // Show dataDivision in the console
  168. console.log("dataDivision:", dataDivision);
  169.  
  170. // Process data for each battle ID
  171. idbattle.forEach(id => {
  172. processDataForId(id);
  173. });
  174.  
  175. // Show emptyBattle in the console
  176. console.log("emptyBattle:", emptyBattle);
  177. console.log("city name:", citynameA);
  178.  
  179.  
  180. // Add a small delay before calling displayResults
  181. setTimeout(displayResults, 3000);
  182. } catch (error) {
  183. console.error("Error:", error);
  184. }
  185. }
  186.  
  187. // Call the main function to start the script
  188. main();
  189. })();