Vault - Max $

Automatically maxes out the deposit input in a vault

目前為 2024-09-24 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Vault - Max $
// @namespace    Titanic_
// @version      1.3
// @description  Automatically maxes out the deposit input in a vault
// @license      MIT
// @author       Titanic_ [2968477]
// @match        https://www.torn.com/properties.php*
// @grant        window.onurlchange
// ==/UserScript==

// YOU CAN CHANGE THESE
const beepLifeChanged = false // by default, it will not make a sound alert if your life bar changes
const beepMoneyChanged = false // by default, it will not make a sound alert if your wallet amount changes

// DONT TOUCH BELOW
let storedLife = 0;
let storedMoney = 0;
let ran = 0;

const observer = new MutationObserver(() => {
    if (window.location.href.includes("tab=vault")) {
        inputCheck();
    }
});

observer.observe(document.body, { childList: true, subtree: true });

function inputCheck() {
    setTimeout(function() {
        if (document.querySelector('.input-money-group > .input-money')) {
            max();
            checkStats();
        }
    }, 300);
}

function max() {
    let $inputVisible = document.querySelector("form.right > div.torn-divider > div.input-money-group > input.input-money");
    let $inputHidden = document.querySelectorAll("form.right > div.torn-divider > div.input-money-group > input.input-money")[1];
    let value = parseInt($inputHidden.value) || 0;
    let amountOnHand = parseInt($("[class^='value_']").attr("data-money"));

    if(amountOnHand > 0) {
        value += amountOnHand;
        $inputVisible.value = value;
        $inputVisible.dispatchEvent(new Event("input", { bubbles: true }));
    }

    var button = $('input[type="submit"].torn-btn.disabled[value="DEPOSIT"][disabled]');
    button.prop('disabled', false).removeClass("disabled");
}

function checkStats() {
    if(!ran) {
        if(!storedMoney) {
            let onHand = parseInt($("[class^='value_']").attr("data-money"))
            onHand = Number(onHand)

            storedMoney = onHand;
            console.log("Updated stored money to", storedMoney);
        }
        if(!storedLife) {
            let lifeBar = $("[class*='bar'][class*='life']");
            let lifeVal = $(lifeBar).find("[class*='bar-value']").text().split("/")[0].trim();
            lifeVal = Number(lifeVal);

            storedLife = lifeVal;
            console.log("Updated stored life to", storedLife);
        }

        ran = 1;
        return;
    }
    console.log("Checking stats");

    let lifeBar = $("[class*='bar'][class*='life']");
    let lifeVal = $(lifeBar).find("[class*='bar-value']").text().split("/")[0].trim();
    lifeVal = Number(lifeVal);

    let onHand = parseInt($("[class^='value_']").attr("data-money"))
    onHand = Number(onHand)

    if(onHand !== storedMoney && beepMoneyChanged) {
        storedMoney = onHand;
        beep();
    }

    if(lifeVal !== storedLife && beepLifeChanged) {
        beep();
        storedLife = lifeVal;
    }
}

var audioCtx = new (window.AudioContext || window.webkitAudioContext || window.audioContext);

function beep(duration, frequency, volume, type, callback) {
    var oscillator = audioCtx.createOscillator();
    var gainNode = audioCtx.createGain();

    oscillator.connect(gainNode);
    gainNode.connect(audioCtx.destination);

    if (volume){gainNode.gain.value = volume;}
    if (frequency){oscillator.frequency.value = frequency;}
    if (type){oscillator.type = type;}
    if (callback){oscillator.onended = callback;}

    oscillator.start(audioCtx.currentTime);
    oscillator.stop(audioCtx.currentTime + ((duration || 500) / 1000));
};