Warning: fopen(/www/sites/update.greasyfork.icu/index/store/forever/2b5e09c9cdd5d550e13c7faac61fd11f.js): failed to open stream: No space left on device in /www/sites/update.greasyfork.icu/index/scriptControl.php on line 65
// ==UserScript== // @name New Something c00L // @namespace erepFarm // @version 0.3.666 // @description Too lazy to do something // @author You // @match https://www.erepublik.com/en // @grant none // @run-at document-end // @downloadURL none // ==/UserScript== (function() { // Main function to perform the main task async function mainFunction() { let energymin = 10; let aircraft = false; let groundWeaponUse = true; let abWeaponUse = false; let weapQu = -1; let groundWeaponQ = 7; let abWeaponQ = 5; let energy = erepublik.citizen.energy; const ablow = 22000; const abhigh = 30000; const gblow = 180000000; const gbhigh = 800000000; if (aircraft == true){ let low = ablow; let high = abhigh; createDivElement('aircraft', 'sidebar', 'Aicraft: '); createDivElement('low', 'sidebar', 'Low Damage: '); displayValueInHtml('low', low); createDivElement('high', 'sidebar', 'High Damage: '); displayValueInHtml('high', high); createDivElement('useweapon', 'sidebar', 'Activate Weapon: '); displayValueInHtml('useweapon', abWeaponUse); if(abWeaponUse == true){ weapQu = abWeaponQ; } console.log("weapon Quality:",weapQu); } else { let low = gblow; let high = gbhigh; createDivElement('ground', 'sidebar', 'Ground: '); createDivElement('low', 'sidebar', 'Low Damage: '); displayValueInHtml('low', low); createDivElement('high', 'sidebar', 'High Damage: '); displayValueInHtml('high', high); createDivElement('useweapon', 'sidebar', 'Activate Weapon: '); displayValueInHtml('useweapon', groundWeaponUse); if(groundWeaponUse == true){ weapQu = groundWeaponQ; } console.log("weapon Quality:",weapQu); } createDivElement('emptyBattle', 'sidebar', 'Battle List: '); createDivElement('list', 'sidebar', ''); if(energy > energymin){ try { console.log("Aircraft? ", aircraft); let _token = csrfToken; let countryLocationId = erepublik.citizen.countryLocationId; let division; if(aircraft == true){division = 11;} else {division = erepublik.citizen.division;} const zone = await fetchData("https://www.erepublik.com/en/military/campaignsJson/citizen"); // Add a delay of 0.8 seconds await delay(2000); const list = await fetchData("https://www.erepublik.com/en/military/campaignsJson/list"); await delay(2000); //separate battle target to array for (const battleId in list.battles) { if (list.battles.hasOwnProperty(battleId)) { const battle = list.battles[battleId]; const zoneId = zone.battles[battleId]; const battleType = battle.war_type; const round = battle.zone_id; const rnow = round; let battleZoneId; let end; if(zoneId && aircraft == true){ battleZoneId = zoneId.aircraftZoneId; } else { battleZoneId = battleZoneId = zoneId.groundZoneId; } if(battleType == "direct"){ const inv = battle.inv.id; const def = battle.def.id; if (inv == countryLocationId || def == countryLocationId){ const invpo = battle.inv.points; const devpo = battle.def.points; const point = invpo - devpo; const campaign = Math.abs(point); const region = battle.region.name; const batstaturl = `https://www.erepublik.com/en/military/battle-stats/${battleId}/${division}/${battleZoneId}`; const getbatstat = await fetchData(batstaturl); end = getbatstat.zone_finished; let deffend = false; if (countryLocationId == def){ deffend = true; } console.log(region," deffend?",deffend); await delay(2000); if(end == false){ const payloadBStat = payloadStat(battleId, round, rnow, division, battleZoneId, _token); const stat = await battleStat(payloadBStat); const empty = checkFighterDataEmpty(stat, countryLocationId); console.log(region," end?",end); console.log(region,"empty?",empty); if (empty == true){ //check damage per hit const inventoryLoad = inventoryPayload(battleId, countryLocationId, battleZoneId, _token); const inventory = await inventoryCheck(inventoryLoad); let pool = inventory.poolEnergy; const listweapon = inventory.weapons; const vehicles = inventory.vehicles; let totDamage = 0; // Find the object with quality 10 in the weapons response array const objectWithQuality = listweapon.find(item => item.quality === weapQu); // Get the value of the 'amount' property if the object is found let weaponAmount; let dph; if (objectWithQuality) { weaponAmount = objectWithQuality.amount; dph = objectWithQuality.damageperHit; console.log("Damage/hit: ",dph); } //skin const skinRecommended = vehicles.find(skin => skin.isRecommended === true); let skinId; let skinBonus; if (skinRecommended) { skinId = skinRecommended.id; skinBonus = parseInt(skinRecommended.countryData.damageBonus); console.log("bonus: ",skinBonus); } let percentage = skinBonus/100; console.log("persen", skinBonus); let damageBonus = dph + (dph * percentage); console.log("Damage bonus: ",damageBonus); //check opposite total damage const opposite = checkFighterDataEmpty(stat, def); console.log (region," opposite empty?",opposite); if (opposite == false){ totDamage = calculateTotalValue(stat, def) } const linkText = `${region} - ${totDamage}`; const linkUrl = `https://www.erepublik.com/en/military/battlefield/${battleId}/${battleZoneId}`; displayLinkInHtml('list', linkText, linkUrl); console.log("Total Damage opposite: ",totDamage); } await delay(2500); } console.log("--------------"); } } } } } catch (error) { console.error("Error fetching data:", error); } } } //list of function // Function to send GET request and fetch JSON data async function fetchData(url) { try { const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { throw new Error(`Failed to fetch data from ${url}: ${error.message}`); } } // Function to introduce a delay function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } // Function to construct the payload from variables function payloadStat(battleId, zoneId, round, division, battleZoneId, _token) { const action = "battleStatistics"; const type = "damage"; const leftPage = 1; const rightPage = 1; return { battleId, zoneId, action, round, division, battleZoneId, type, leftPage, rightPage, _token }; } // Function to send the payload using POST request async function battleStat(payload) { const url = "https://www.erepublik.com/en/military/battle-console"; try { const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: Object.keys(payload) .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(payload[key])}`) .join('&') }); const responseData = await response.json(); return responseData; } catch (error) { console.error("Error:", error); return null; } } // Function to check if country.fighterData is empty and push to new array if empty function checkFighterDataEmpty(responseData, countryLocationId) { if (responseData && responseData[countryLocationId] && responseData[countryLocationId]["fighterData"]) { const fighterData = responseData[countryLocationId]["fighterData"]; const isFighterDataEmpty = Object.keys(fighterData).length === 0; return isFighterDataEmpty; } else { console.log(`Could not find ${countryLocationId}.fighterData in the response.`); } } // Function to calculate the total value function calculateTotalValue(data, countryId) { let totalValue = 0; const fighterData = data[countryId]?.fighterData || {}; for (const key in fighterData) { if (fighterData.hasOwnProperty(key)) { const value = fighterData[key].value; if (typeof value === 'string') { const parsedValue = parseInt(value.replace(/,/g, ''), 10); if (!isNaN(parsedValue)) { totalValue += parsedValue; } } } } return totalValue; } //payload for inventory function inventoryPayload(battleId, sideCountryId, battleZoneId, _token) { return { battleId, sideCountryId, battleZoneId, _token }; } //function to check inventory async function inventoryCheck(payload) { const url = "https://www.erepublik.com/en/military/fightDeploy-getInventory"; try { const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: Object.keys(payload) .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(payload[key])}`) .join('&') }); const responseData = await response.json(); return responseData; } catch (error) { console.error("Error:", error); return null; } } // Function to create a new div element inside a parent element function createDivElement(divId, parentId, textContent) { const parentElement = document.querySelector(`.${parentId}`); if (parentElement) { const newDiv = document.createElement('div'); newDiv.id = divId; newDiv.textContent = textContent; parentElement.appendChild(newDiv); } else { console.error(`Parent element with class '${parentId}' not found.`); } } // Function to display any value in HTML function displayValueInHtml(elementId, value) { const element = document.getElementById(elementId); if (element) { element.textContent = `${element.textContent} ${value}`; } else { console.error(`Element with ID '${elementId}' not found.`); } } function displayLinkInHtml(containerId, linkText, linkUrl) { const containerElement = document.getElementById(containerId); if (containerElement) { const linkElement = document.createElement('a'); linkElement.href = linkUrl; linkElement.textContent = linkText; containerElement.appendChild(linkElement); containerElement.appendChild(document.createElement('br')); } else { console.error(`Container element with ID '${containerId}' not found.`); } } //end of line // Call the main function when the page loads window.addEventListener('load', mainFunction); })();