Melvor offline cap remover

Removes 12hr offline cap

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Melvor offline cap remover
// @version      0.3.0
// @description  Removes 12hr offline cap
// @author       8992
// @match        https://*.melvoridle.com/*
// @exclude      https://wiki.melvoridle.com/*
// @grant        none
// @namespace    http://tampermonkey.net/
// @noframes
// ==/UserScript==

let times = null;
let cloudLoaded = false;

let loadCheckInterval = setInterval(() => {
  if (isLoaded && !currentlyCatchingUp && !modalIsOpen) {
    clearInterval(loadCheckInterval);
    extraOffline();
  }
}, 200);

function extraOffline() {
  let offlineData = JSON.parse(window.localStorage.getItem("12hr"));
  if (offlineData != null) {
    //remove limit from updateOffline function then overwrite
    patchCode(updateOffline, /> *43200000/, "== 43200000");
    //"fix" issue with sample_from_binomial
    patchCode(
      sample_from_binomial,
      /(let binomial[^;]+;)/,
      "$1if (binomial.length > numberTrials) return Math.floor(numberTrials * chance);"
    );
    offlineData.timestamp = Math.min(new Date().getTime(), offlineData.timestamp + 43200000);
    console.log(
      `Calculating additional ${Math.floor(
        (new Date().getTime() - offlineData.timestamp) / 1000 / 60 / 60
      )}hrs of offline time`
    );
    window.offline = offlineData;
    offlinePause = true;
    pauseOfflineAction(offline.skill);
    offlineCatchup();
    offlinePause = false;
    window.localStorage.removeItem("12hr");
  }
}

function patchCode(code, match, replacement) {
  const codeString = code
    .toString()
    .replace(match, replacement)
    .replace(/^function (\w+)/, "window.$1 = function");
  eval(codeString);
}

setTimeout(() => {
  //fetch offline save data
  times = {
    0: ["", "-1-", "-2-", "-3-", "-4-"].map((a) => getItem("MI-A04" + a + "offline")),
    1: [],
  };

  const _toggleCharacterSelectionView = toggleCharacterSelectionView;
  window.toggleCharacterSelectionView = () => {
    if (!cloudLoaded) {
      for (let i = 0; i < 5; i++) {
        if (playFabSaves[i] !== null) {
          times[1][i] = getItemFromSave(playFabSaves[i], "offline");
        } else if (storedCloudSaves[i] !== null) {
          times[1][i] = getItemFromSave(storedCloudSaves[i], "offline");
        } else times[1][i] = null;
      }
      cloudLoaded = true;
    }
    _toggleCharacterSelectionView();
  };

  const _selectCharacter = selectCharacter;
  window.selectCharacter = (char, confirmed = false) => {
    if (confirmed || !connectedToCloud) {
      let offline = times[currentView][char];
      if (
        offline != null &&
        typeof offline == "object" &&
        typeof offline.timestamp == "number" &&
        new Date().getTime() - offline.timestamp > 43200000
      ) {
        window.localStorage.setItem("12hr", JSON.stringify(offline));
      } else {
        window.localStorage.removeItem("12hr");
      }
    }
    _selectCharacter(char, confirmed);
  };
}, 100);