Torn Auto Gym

This script train your lowest battle stat when your energy over 25, while you're in the gym for torn.com

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Torn Auto Gym
// @namespace   Violentmonkey Scripts
// @match       https://www.torn.com/gym.php*
// @grant       none
// @version     1.0
// @author      shockingchick
// @description This script train your lowest battle stat when your energy over 25, while you're in the gym for torn.com
// @license WasrCommunity
// ==/UserScript==

// Function to monitor energy and train the lowest stat if energy is over 25
function monitorEnergyAndTrain() {
  // Select the element containing the energy value
  const energyElement = document.querySelector('.bar-value___NTdce');

  if (energyElement) {
    // Extract the energy value
    const energyValue = parseInt(energyElement.textContent.split('/')[0], 10);

    // Check if the energy value is more than 25
    if (energyValue > 25) {
      console.log(`Energy is ${energyValue}, training the lowest stat...`);
      // Call the function to train the lowest stat
      trainLowestStat();
    } else {
      console.log(`Energy is ${energyValue}, waiting until it's over 25...`);
    }
  } else {
    console.error("Energy element not found.");
  }
}

// Function to check the property values and click the TRAIN button for the lowest one
function trainLowestStat() {
  // Select the elements containing the property values
  const stats = [
    {
      name: 'Speed',
      valueElement: document.querySelector('.speed___qNMTy .propertyValue___wopyE'),
      trainButton: document.querySelector('.speed___qNMTy button[aria-label="Train speed"]')
    },
    {
      name: 'Dexterity',
      valueElement: document.querySelector('.dexterity___6ayVQ .propertyValue___wopyE'),
      trainButton: document.querySelector('.dexterity___6ayVQ button[aria-label="Train dexterity"]')
    },
    {
      name: 'Strength',
      valueElement: document.querySelector('.strength___UwX1Y .propertyValue___wopyE'),
      trainButton: document.querySelector('.strength___UwX1Y button[aria-label="Train strength"]')
    },
    {
      name: 'Defense',
      valueElement: document.querySelector('.defense___LITyA .propertyValue___wopyE'),
      trainButton: document.querySelector('.defense___LITyA button[aria-label="Train defense"]')
    }
  ];

  // Filter out stats that don't exist on the page
  const validStats = stats.filter(stat => stat.valueElement && stat.trainButton);

  if (validStats.length === 0) {
    console.error("No valid stats found.");
    return;
  }

  // Find the stat with the lowest value
  let lowestStat = validStats[0];
  validStats.forEach(stat => {
    const statValue = parseFloat(stat.valueElement.textContent);
    if (statValue < parseFloat(lowestStat.valueElement.textContent)) {
      lowestStat = stat;
    }
  });

  // Log the stat with the lowest value
  console.log(`Lowest stat is: ${lowestStat.name} with value ${lowestStat.valueElement.textContent}`);

  // Click the corresponding TRAIN button
  lowestStat.trainButton.click();
  console.log(`${lowestStat.name} TRAIN button clicked.`);
}

// Start a loop to monitor the energy every 5 seconds
setInterval(monitorEnergyAndTrain, 5000);