Auto Work at night

try to take over the world!

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Auto Work at night
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.erepublik.com/en/main/messages-inbox
// @grant        none
// ==/UserScript==

var bufferBeforeEat = 1600;

(function() {

    main();


function isTimeToWork()
{
   var totalCapacity = erepublik.citizen.energyToRecover * 2;
   var currentEnergy = erepublik.citizen.energy + erepublik.citizen.energyFromFoodRemaining;

   var result = totalCapacity <= currentEnergy + bufferBeforeEat;
  // alert(totalCapacity - currentEnergy - bufferBeforeEat)
   return result;
}

function isHomePage()
{
    var isHome = $j("#hpTopNews").length == 1;
    return isHome;
}

function gotoHomePage()
{
    location.href = "https://www.erepublik.com/en";
}

function gotoCompanies()
{
    location.href = "https://www.erepublik.com/en/economy/myCompanies" + "?mine=mine-script";
}

var isActivatedTracking = false;
var loadTime = null;
function tryToRedirectHome() {
    if(loadTime == null)    {
        loadTime = new Date();
    }
    var now = new Date();
    var isTooMuch = now.getTime() - loadTime.getTime() > 1*10*1000;
    if(isTooMuch || erepublik.citizen.energy == 0){
        gotoHomePage();
    }
    else{
        if(!isActivatedTracking){
            isActivatedTracking = true;
            setInterval(tryToRedirectHome, 10000);
        }

    }
}

function workNow()
{
    var availableCountToWork = 2;
    var counter = 0;

    // remove all checkboxes
    $j("div.list_group .listing:not(div.disabled) a.owner_work").removeClass("active");

    $j("div.list_group .listing:not(div.disabled) a.owner_work")
        .each(function(idx, item)
              {
       // debugger
                 if(idx >= availableCountToWork)
                     return;
                 //alert(counter);
                 $j(item).click();
                 counter++;
              });

  //  $j("#start_production").click();
}




function main()
{
    var isTime = isTimeToWork();
    var isHome = isHomePage();
debugger
    var isMyCompaniesScreen = window.location.href.includes("erepublik.com/en/economy/myCompanie");
    var isMineLink = window.location.search.includes("mine-script");

    if(isHome && isTime){
        gotoCompanies();
    }
    else if(isMineLink)
    {
        if(isMyCompaniesScreen)
        {
            workNow();
        }

        tryToRedirectHome();
    }
    else
    {
        // todo - try to redirect home
        tryToRedirectHome();
    }

}



})();