Greasy Fork 还支持 简体中文。

Auto Work at night

try to take over the world!

目前為 2019-01-28 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
    }

}



})();