Torn - OC Travel Restrictions ## NOT CURRENTLY WORKING ON OC 2.0 ##

Disables travel for individual countries based on flight type if you would be late for an organized crime. Includes a button to enable or disable the script.

目前为 2025-03-05 提交的版本。查看 最新版本

// ==UserScript==
// @name         Torn - OC Travel Restrictions ## NOT CURRENTLY WORKING ON OC 2.0 ##
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Disables travel for individual countries based on flight type if you would be late for an organized crime. Includes a button to enable or disable the script.
// @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 () {

    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;

    const travelTimes = {
        "tab4-1": {
            mexico: 1560000 * 2,
            cayman: 2100000 * 2,
            canada: 2460000 * 2,
            hawaii: 8040000 * 2,
            uk: 9540000 * 2,
            argentina: 10020000 * 2,
            switzerland: 10500000 * 2,
            japan: 13500000 * 2,
            china: 14520000 * 2,
            uae: 16260000 * 2,
            "south-africa": 17820000 * 2
        },
        "tab4-2": {
            mexico: 1080000 * 2,
            cayman: 1500000 * 2,
            canada: 1740000 * 2,
            hawaii: 5640000 * 2,
            uk: 6660000 * 2,
            argentina: 7020000 * 2,
            switzerland: 7380000 * 2,
            japan: 9480000 * 2,
            china: 10140000 * 2,
            uae: 11400000 * 2,
            "south-africa": 12480000 * 2
        },
        "tab4-3": {
            mexico: 780000 * 2,
            cayman: 1080000 * 2,
            canada: 1200000 * 2,
            hawaii: 4020000 * 2,
            uk: 4800000 * 2,
            argentina: 4980000 * 2,
            switzerland: 5280000 * 2,
            japan: 6780000 * 2,
            china: 7260000 * 2,
            uae: 8100000 * 2,
            "south-africa": 8940000 * 2
        },
        "tab4-4": {
            mexico: 480000 * 2,
            cayman: 660000 * 2,
            canada: 720000 * 2,
            hawaii: 2400000 * 2,
            uk: 2880000 * 2,
            argentina: 3000000 * 2,
            switzerland: 3180000 * 2,
            japan: 4080000 * 2,
            china: 4320000 * 2,
            uae: 4860000 * 2,
            "south-africa": 5340000 * 2
        }
    };

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

	const toggleButton = document.createElement('button');
	toggleButton.innerText = 'OC';
	toggleButton.style = isEnabled
		? 'padding: 5px 5px; border-radius: 5px; background-color: #555555; color: lightgreen; border: none; cursor: pointer;'
		: 'padding: 5px px; 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('ocTravelRestriction', isEnabled);
		if (isEnabled) {
			toggleButton.style.color = 'lightgreen';
			applyTravelRestrictions();
		} else {
			toggleButton.style.color = 'white';
			enableFlights();
		}
	};

    const buttonElement = document.querySelector('div.content-title > h4');
    if (buttonElement)
		buttonElement.appendChild(toggleButton);

	if (isEnabled)
		applyTravelRestrictions();

	function applyTravelRestrictions() {
		const warningElements = document.querySelectorAll('.t-red');
		if (warningElements.length === 0) {
			return;
		}

		let validWarningFound = false;

		warningElements.forEach(warningElement => {
			const warningText = warningElement.innerText.trim();
			if (warningText.startsWith("Warning: An organized crime you're participating in will be ready in")) {
				validWarningFound = true;

				const timeMatch = warningText.match(/(\d+) hours? and (\d+) minutes?/);
				if (!timeMatch) {
					console.error("Failed to parse time from warning: ", warningText);
					return;
				}

				const hours = parseInt(timeMatch[1], 10);
				const minutes = parseInt(timeMatch[2], 10);
				const remainingTime = (hours * 60 + minutes) * 60 * 1000;

				disableFlights(remainingTime);
			} else if (warningText.startsWith("Warning: An organized crime you're participating in is ready for initiation")) {
				validWarningFound = true;
				disableFlights(Date.now());
			}
		});
	}

	function disableFlights(remainingTime) {
		Object.keys(travelTimes).forEach(tabId => {
			const travelTab = document.getElementById(tabId);
			const tabTravelTimes = travelTimes[tabId];

			if (travelTab && tabTravelTimes) {
				Object.entries(tabTravelTimes).forEach(([location, time]) => {
					if (time > remainingTime) {
						if (mobileView) {
							const cityFlag = travelTab.querySelector(`.city-flag.${location}`);
							if (cityFlag) {
								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.setAttribute('style', 'display: none;');
							}
						} else {
							const button = travelTab.querySelector(`.raceway.${location}`);
							if (button) {
								button.style.pointerEvents = 'none';
								button.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', '')
			);
		} else {
			document.querySelectorAll('.raceway').forEach(button => {
				button.style.pointerEvents = 'auto';
				button.style.opacity = '1';
			});
		}
	}

	const observer = new MutationObserver((mutationsList, observer) => {
		const pcTravelButtons = document.querySelectorAll('.raceway');
		const mobileTravelButtons = document.querySelectorAll('.travel-info-table-list.ui-accordion-header.ui-helper-reset.ui-state-default.ui-corner-all.ui-accordion-icons');
		if (mobileTravelButtons.length > 0) {
			mobileView = true;
			if (isEnabled) applyTravelRestrictions();
			observer.disconnect();
		} else if (!mobileView && pcTravelButtons.length > 0) {
			if (isEnabled) applyTravelRestrictions();
			observer.disconnect();
		}
	});

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

})();

QingJ © 2025

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