Torn - Cash Travel Restrictions

Disables travel for individual countries if you do not have enough to purchase plushies/flowers. This choice will be made by whichever is more expensive. Edit the numbers inside the script if you will need less/more for each country, and the travel capacity if yours is not 29. Switzerland is set to 500k for two rehab sessions. This doesn't take into account the ticket cost in standard flights.

目前为 2024-12-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         Torn - Cash Travel Restrictions
// @namespace    http://www.torn.com/
// @version      0.1
// @description  Disables travel for individual countries if you do not have enough to purchase plushies/flowers. This choice will be made by whichever is more expensive. Edit the numbers inside the script if you will need less/more for each country, and the travel capacity if yours is not 29. Switzerland is set to 500k for two rehab sessions. This doesn't take into account the ticket cost in standard flights.
// @author       Baccy
// @match        https://www.torn.com/travelagency.php
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @grant        none
// ==/UserScript==

(function () {

    const travelCapacity = 29; // Change if your capacity is not 29

    const travelCosts = { // Change numbers if you will need less or more for the item you want to purchase when travelling to that country
        mexico: 10000 * travelCapacity, // Jaguar Plushie cost
        cayman: 4000 * travelCapacity, // Banana Orchid cost
        canada: 600 * travelCapacity, // Crocus cost
        hawaii: 700 * travelCapacity, // Orchid cost
        uk: 5000 * travelCapacity, // Heather cost
        argentina: 500 * travelCapacity, // Ceibo Flower cost
        switzerland: 500000, // 2 rehabs cost
        japan: 500 * travelCapacity, // Cherry Blossom cost
        china: 5000 * travelCapacity, // Peony cost
        uae: 14000 * travelCapacity, // Camel Plushie cost
        'south-africa': 2000 * travelCapacity // African Violet cost
    };

    let mobileView;
    if (document.querySelector('.travel-info-table-list.ui-accordion-header.ui-helper-reset.ui-state-default.ui-corner-all.ui-accordion-icons'))
        mobileView = true;

    let userMoney;
    let cityFlags = {};

    function getMoney() {
        // Get your money from the sidebar element
        const moneyElement = document.querySelector('[data-money]');
        if (!moneyElement) {
            console.error('Unable to find element with data-money attribute.');
            return;
        }
        userMoney = parseInt(moneyElement.getAttribute('data-money'), 10);
    }

    let isEnabled = JSON.parse(localStorage.getItem('cashTravelRestriction')) ?? true;

    const toggleButton = document.createElement('button');
    toggleButton.innerText = isEnabled ? '$ Disable $' : '$ Enable $';
    toggleButton.style = 'padding: 5px 10px; border-radius: 5px; background-color: #555555; color: white; border: none; cursor: pointer;';
	if (mobileView) {
		toggleButton.ontouchstart = toggleButton.onmousedown = () => {
			toggleButton.style.backgroundColor = '#444444';
		};

		toggleButton.ontouchend = toggleButton.onmouseup = toggleButton.onmouseleave = () => {
			toggleButton.style.backgroundColor = '#555555';
		};
	} else {
		toggleButton.onmouseover = () => {
			toggleButton.style.backgroundColor = '#444444';
		};
		toggleButton.onmouseout = () => {
			toggleButton.style.backgroundColor = '#555555';
		};
	}

    toggleButton.onclick = () => {
        isEnabled = !isEnabled;
        localStorage.setItem('cashTravelRestriction', isEnabled);
        toggleButton.innerText = isEnabled ? '$ Disable $' : '$ Enable $';
        if (isEnabled) {
            applyTravelRestrictions();
        } else if (!isEnabled) {
            enableFlights();
        }
    };

    if ($('div.content-title > h4').length > 0)
        $('div.content-title > h4').append(toggleButton);

    function getCountryElements() {
        Object.keys(travelCosts).forEach((location) => {
			if (mobileView) {
				const flags = document.querySelectorAll(`.city-flag.${location}`);
				if (flags.length > 0) {
					cityFlags[location] = flags;
				}
			}
			if (!mobileView) {
				const flags = document.querySelectorAll(`.raceway.${location}`);
				if (flags.length > 0) {
					cityFlags[location] = flags;
				}
			}
        });
    }

    function applyTravelRestrictions() {
        Object.entries(cityFlags).forEach(([location, flags]) => {
            const requiredCost = travelCosts[location];
            if (userMoney < requiredCost) {
                flags.forEach((cityFlag) => {
					if (mobileView) {
						const travelOption = cityFlag.closest(
							'.travel-info-table-list.ui-accordion-header.ui-helper-reset.ui-state-default.ui-corner-all.ui-accordion-icons'
						);
						if (travelOption) {
							travelOption.style.display = 'none';
						}
					}
					if (!mobileView) {
						flags.forEach((cityFlag) => {
							cityFlag.style.pointerEvents = 'none';
							cityFlag.style.opacity = '0.5';
						});
					}
                });
            }
        });
    }

    function enableFlights() {
        if (mobileView) {
            document.querySelectorAll('.travel-info-table-list.ui-accordion-header.ui-helper-reset.ui-state-default.ui-corner-all.ui-accordion-icons').forEach((travelOption) => {
                travelOption.setAttribute('style', '');
            });
        }
		if (!mobileView) {
            document.querySelectorAll('.raceway').forEach(button => {
                button.style.pointerEvents = 'auto';
                button.style.opacity = '1';
            });
        }
    }

	function init() {
		getMoney();
		getCountryElements();
		if (isEnabled) applyTravelRestrictions();
	}

	init();

    const observer = new MutationObserver((mutationsList, observer) => {
		if (mobileView) {
			const travelButtons = document.querySelectorAll('.city-flag');
			if (travelButtons.length > 0) {
				init();
				setTimeout(() => {
					observer.disconnect();
				}, 1000);
			}
		}
		if (!mobileView) {
			const travelButtons = document.querySelectorAll('.raceway');
			if (travelButtons.length > 0) {
				init();
				setTimeout(() => {
					observer.disconnect();
				}, 1000);
			}
		}
    });

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址