Torn - OC Travel Restrictions

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. Green 'OC' means enabled.

  1. // ==UserScript==
  2. // @name Torn - OC Travel Restrictions
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.3
  5. // @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. Green 'OC' means enabled.
  6. // @author Baccy
  7. // @match https://www.torn.com/page.php?sid=travel
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=torn.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function apply() {
  16. const elements = {
  17. "Mexico": { pc: "Mexico - Ciudad Juarez", mobile: '/images/v2/travel_agency/flags/fl_mexico.svg' },
  18. "Cayman Islands": { pc: "Cayman Islands - George Town", mobile: '/images/v2/travel_agency/flags/fl_cayman_islands.svg' },
  19. "Canada": { pc: "Canada - Toronto", mobile: '/images/v2/travel_agency/flags/fl_canada.svg' },
  20. "Hawaii": { pc: "Hawaii - Honolulu", mobile: '/images/v2/travel_agency/flags/fl_hawaii.svg' },
  21. "United Kingdom": { pc: "United Kingdom - London", mobile: '/images/v2/travel_agency/flags/fl_uk.svg' },
  22. "Argentina": { pc: "Argentina - Buenos Aires", mobile: '/images/v2/travel_agency/flags/fl_argentina.svg' },
  23. "Switzerland": { pc: "Switzerland - Zurich", mobile: '/images/v2/travel_agency/flags/fl_switzerland.svg' },
  24. "Japan": { pc: "Japan - Tokyo", mobile: '/images/v2/travel_agency/flags/fl_japan.svg' },
  25. "China": { pc: "China - Beijing", mobile: '/images/v2/travel_agency/flags/fl_china.svg' },
  26. "UAE": { pc: "UAE - Dubai", mobile: '/images/v2/travel_agency/flags/fl_uae.svg' },
  27. "South Africa": { pc: "South Africa - Johannesburg", mobile: '/images/v2/travel_agency/flags/fl_south_africa.svg' }
  28. };
  29.  
  30. const dataElement = document.querySelector('#travel-root');
  31. if (dataElement) {
  32. const dataModel = dataElement.getAttribute('data-model');
  33. const data = JSON.parse(dataModel.replace(/"/g, '"'));
  34.  
  35. data.destinations.forEach(destination => {
  36. const country = destination.country;
  37. if (destination[active] && destination[active].ocReadyBeforeBack) {
  38. const elementData = elements[country];
  39. if (elementData) {
  40. if (mobile) {
  41. const element = document.querySelector(`[src="${elementData.mobile}"]`);
  42. if (element) {
  43. const parent = element.parentElement.parentElement.parentElement.parentElement;
  44. parent.style.display = 'none';
  45. parent.classList.add('oc-restriction');
  46. }
  47. } else {
  48. const element = document.querySelector(`[aria-label="${elementData.pc}"]`);
  49. if (element) {
  50. element.nextSibling.style.opacity = '0.5';
  51. element.classList.add('oc-restriction');
  52. const parent = element.parentElement;
  53. parent.style.pointerEvents = 'none';
  54. }
  55. }
  56. }
  57. }
  58. });
  59. }
  60. }
  61.  
  62. function remove() {
  63. const elements = document.querySelectorAll('.oc-restriction');
  64. elements.forEach(element => {
  65. if (mobile) {
  66. element.style.display = '';
  67. } else {
  68. element.nextSibling.style.opacity = '';
  69. element.classList.remove('oc-restriction');
  70. const parent = element.parentElement;
  71. parent.style.pointerEvents = '';
  72. }
  73. });
  74. }
  75.  
  76. function init() {
  77. const travelTabs = document.querySelector('fieldset[class^="travelTypeSelector"]');
  78. let enabled = JSON.parse(localStorage.getItem('ocTravelRestriction')) ?? true;
  79.  
  80. const checkedTab = [...document.querySelectorAll('[aria-checked]')].find(tab => tab.getAttribute('aria-checked') === "true");
  81. if (checkedTab) active = checkedTab.getAttribute('value');
  82.  
  83. const observer = new MutationObserver(() => {
  84. const checkedTab = [...document.querySelectorAll('[aria-checked]')].find(tab => tab.getAttribute('aria-checked') === "true");
  85. if (checkedTab) active = checkedTab.getAttribute('value');
  86. if (enabled) {
  87. remove();
  88. apply();
  89. }
  90. });
  91. observer.observe(travelTabs, { childList: true, subtree: true, attributes: true });
  92.  
  93. const header = Array.from(document.querySelectorAll('h4')).find(el => el.childNodes[0]?.nodeValue.trim() === 'Travel Agency');
  94. const button = document.createElement('button');
  95. button.textContent = 'OC';
  96. button.style.cssText = 'margin-left: 10px; padding: 5px 10px; border-radius: 5px; background-color: #555; cursor: pointer;';
  97. button.style.color = enabled ? 'lightgreen' : 'white';
  98. button.addEventListener('click', () => {
  99. enabled = !enabled;
  100. localStorage.setItem('ocTravelRestriction', enabled);
  101. if (enabled) {
  102. apply();
  103. button.style.color = 'lightgreen';
  104. } else {
  105. remove();
  106. button.style.color = 'white';
  107. }
  108. });
  109. button.addEventListener("mouseenter", () => {
  110. button.style.backgroundColor = "#444";
  111. });
  112. button.addEventListener("mouseleave", () => {
  113. button.style.backgroundColor = "#555";
  114. });
  115. if (header) header.appendChild(button);
  116.  
  117. if (enabled) apply();
  118. }
  119.  
  120. let mobile = false;
  121. let loaded = false;
  122. let active;
  123. let data;
  124.  
  125. function wait() {
  126. const travelTabs = document.querySelector('fieldset[class^="travelTypeSelector"]');
  127. if (travelTabs) {
  128. const mobileElement = document.querySelector('[src="/images/v2/travel_agency/flags/fl_uk.svg"]');
  129. if (mobileElement || document.querySelector('[aria-label="United Kingdom - London"]')) {
  130. if (mobileElement) mobile = true;
  131. return true;
  132. }
  133. }
  134. return false;
  135. }
  136.  
  137. loaded = wait();
  138. if (loaded) {
  139. init();
  140. } else {
  141. const observer = new MutationObserver(() => {
  142. loaded = wait();
  143. if (loaded) {
  144. init();
  145. observer.disconnect();
  146. }
  147. });
  148. observer.observe(document.body, { childList: true, subtree: true });
  149. }
  150. })();

QingJ © 2025

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