// ==UserScript== // @name eRep Energy Recovery // @name:ro Recuperare energie eRep // @description Energy recovery for eRebuglik // @description:ro Recuperare energie pentru eRebuglik // @namespace http://www.linuxmint.ro/ // @version 1.5 // @license CC BY 4.0 // @author Nicolae Crefelean // @include http*://www.erepublik.com/* // @grant none // @downloadURL none // ==/UserScript== if (typeof jQuery !== "undefined") { jQuery(function() { var gameInactivity = 0, gameRefresh = 0; // returns true|false whether energy can be recovered (bar not filled) function energyAvailable() { var energyToLoad = getMaxEnergy - getEnergy; return recoverableEnergy() % 2 === 0 && energyToLoad >= 2 && energyToLoad % 2 === 0; } // returns the amount of recoverable energy function recoverableEnergy() { return jQuery('big.tooltip_health_limit').text().trim(); } // return the maximum recoverable energy function getMaxEnergy() { return jQuery('#current_health').text().split("/")[1].trim(); } // return currently loaded energy function getEnergy() { return jQuery('#current_health').text().split("/")[0].trim(); } // return true|false whether the energy can be recovered with food function foodAvailable() { return jQuery("#foodText").length && jQuery("#eat_food_text").val().trim() == jQuery("#foodText").text().trim() || jQuery("#heal_btn").length && jQuery("#heal_btn").attr("class") == "food_btn"; } // resets the inactivity counter if the user is active in the game jQuery(document).on("click mousemove keyup keydown keypress", function() { gameInactivity = 0; }); // check the user's game activity and feed if not active for more than 5 seconds; also, refresh if inactive for more than 1 hour setInterval(function() { if (energyAvailable() && foodAvailable() && gameInactivity >= 5) { energy.eatFood(); if (gameRefresh > 3600) { location.reload(); gameRefresh = 0; } gameInactivity = 0; } gameInactivity++; gameRefresh++; }, 1000); }); }