Auto Work at night

try to take over the world!

当前为 2019-01-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Auto Work at night
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://www.erepublik.com/en/main/messages-inbox
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. var bufferBeforeEat = 1600;
  12.  
  13. (function() {
  14.  
  15. main();
  16.  
  17.  
  18. function isTimeToWork()
  19. {
  20. var totalCapacity = erepublik.citizen.energyToRecover * 2;
  21. var currentEnergy = erepublik.citizen.energy + erepublik.citizen.energyFromFoodRemaining;
  22.  
  23. var result = totalCapacity <= currentEnergy + bufferBeforeEat;
  24. // alert(totalCapacity - currentEnergy - bufferBeforeEat)
  25. return result;
  26. }
  27.  
  28. function isHomePage()
  29. {
  30. var isHome = $j("#hpTopNews").length == 1;
  31. return isHome;
  32. }
  33.  
  34. function gotoHomePage()
  35. {
  36. location.href = "https://www.erepublik.com/en";
  37. }
  38.  
  39. function gotoCompanies()
  40. {
  41. location.href = "https://www.erepublik.com/en/economy/myCompanies" + "?mine=mine-script";
  42. }
  43.  
  44. var isActivatedTracking = false;
  45. var loadTime = null;
  46. function tryToRedirectHome() {
  47. if(loadTime == null) {
  48. loadTime = new Date();
  49. }
  50. var now = new Date();
  51. var isTooMuch = now.getTime() - loadTime.getTime() > 1*10*1000;
  52. if(isTooMuch || erepublik.citizen.energy == 0){
  53. gotoHomePage();
  54. }
  55. else{
  56. if(!isActivatedTracking){
  57. isActivatedTracking = true;
  58. setInterval(tryToRedirectHome, 10000);
  59. }
  60.  
  61. }
  62. }
  63.  
  64. function workNow()
  65. {
  66. var availableCountToWork = 2;
  67. var counter = 0;
  68.  
  69. // remove all checkboxes
  70. $j("div.list_group .listing:not(div.disabled) a.owner_work").removeClass("active");
  71.  
  72. $j("div.list_group .listing:not(div.disabled) a.owner_work")
  73. .each(function(idx, item)
  74. {
  75. // debugger
  76. if(idx >= availableCountToWork)
  77. return;
  78. //alert(counter);
  79. $j(item).click();
  80. counter++;
  81. });
  82.  
  83. // $j("#start_production").click();
  84. }
  85.  
  86.  
  87.  
  88.  
  89. function main()
  90. {
  91. var isTime = isTimeToWork();
  92. var isHome = isHomePage();
  93. debugger
  94. var isMyCompaniesScreen = window.location.href.includes("erepublik.com/en/economy/myCompanie");
  95. var isMineLink = window.location.search.includes("mine-script");
  96.  
  97. if(isHome && isTime){
  98. gotoCompanies();
  99. }
  100. else if(isMineLink)
  101. {
  102. if(isMyCompaniesScreen)
  103. {
  104. workNow();
  105. }
  106.  
  107. tryToRedirectHome();
  108. }
  109. else
  110. {
  111. // todo - try to redirect home
  112. tryToRedirectHome();
  113. }
  114.  
  115. }
  116.  
  117.  
  118.  
  119. })();