Torn Property Vault Quick Money Input

Add buttons to set money withdraw/deposit inputs to a target amount.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Torn Property Vault Quick Money Input
// @namespace    http://www.tornradio.com/
// @version      0.1
// @description  Add buttons to set money withdraw/deposit inputs to a target amount.
// @author       tornradio [2851045]
// @match        https://www.torn.com/properties.php
// @grant        none
// ==/UserScript==

(function () {
  "use strict";
  const timer = setInterval(function () {
    const area = document.querySelector("div.vault-wrap.container-ask");
    const leftInput = document.querySelector("form.vault-cont.left input.input-money");
    const rightInput = document.querySelector("form.vault-cont.right input.input-money");
    if (!(area && leftInput && rightInput)) {
      return false;
    }
    const vaultBalance = parseInt(leftInput.getAttribute("data-money"));
    const walletBalance = parseInt(rightInput.getAttribute("data-money"));

    clearInterval(timer);
    console.log("Found vault input elements.");

    const fillInputs = (walletBalance, target) => {
      if (walletBalance > target) {
        leftInput.value = "";
        leftInput.dispatchEvent(new Event("input", { bubbles: true }));
        rightInput.value = (walletBalance - target).toString();
        rightInput.dispatchEvent(new Event("input", { bubbles: true }));
      } else if (walletBalance < target) {
        leftInput.value = (target - walletBalance).toString();
        leftInput.dispatchEvent(new Event("input", { bubbles: true }));
        rightInput.value = "";
        rightInput.dispatchEvent(new Event("input", { bubbles: true }));
      }
    };

    const text = document.createElement("span");
    text.innerHTML = "Target wallet value:&nbsp;&nbsp;&nbsp;&nbsp;";
    text.classList.add("m-top10");
    text.classList.add("bold");
    area.parentElement.insertBefore(text, area);
    const zeroBtn = document.createElement("button");
    zeroBtn.innerText = "0";
    zeroBtn.classList.add("torn-btn");
    zeroBtn.onclick = () => {
      fillInputs(walletBalance, 0);
    };
    area.parentElement.insertBefore(zeroBtn, area);

    const fiftyKBtn = document.createElement("button");
    fiftyKBtn.innerText = "50k";
    fiftyKBtn.classList.add("torn-btn");
    fiftyKBtn.onclick = () => {
      fillInputs(walletBalance, 50000);
    };
    area.parentElement.insertBefore(fiftyKBtn, area);

    const twoHunKBtn = document.createElement("button");
    twoHunKBtn.innerText = "200k";
    twoHunKBtn.classList.add("torn-btn");
    twoHunKBtn.onclick = () => {
      fillInputs(walletBalance, 200000);
    };
    area.parentElement.insertBefore(twoHunKBtn, area);

    const oneMBtn = document.createElement("button");
    oneMBtn.innerText = "1M";
    oneMBtn.classList.add("torn-btn");
    oneMBtn.onclick = () => {
      fillInputs(walletBalance, 1000000);
    };
    area.parentElement.insertBefore(oneMBtn, area);

    const twoMBtn = document.createElement("button");
    twoMBtn.innerText = "2M";
    twoMBtn.classList.add("torn-btn");
    twoMBtn.onclick = () => {
      fillInputs(walletBalance, 2000000);
    };
    area.parentElement.insertBefore(twoMBtn, area);

    const fiveMBtn = document.createElement("button");
    fiveMBtn.innerText = "5M";
    fiveMBtn.classList.add("torn-btn");
    fiveMBtn.onclick = () => {
      fillInputs(walletBalance, 5000000);
    };
    area.parentElement.insertBefore(fiveMBtn, area);
  }, 100);
})();