From bd7cfef2ee4b47ba099aa79dd83559d9b13758be Mon Sep 17 00:00:00 2001 From: Matt Holland Date: Wed, 8 Jul 2026 01:51:30 -0400 Subject: [PATCH] Moved code around. Began YATA Foreign Stock Testing. --- travel-time/travel-helper.js | 112 +++++++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 31 deletions(-) diff --git a/travel-time/travel-helper.js b/travel-time/travel-helper.js index 9db4e7d..d786ada 100644 --- a/travel-time/travel-helper.js +++ b/travel-time/travel-helper.js @@ -16,7 +16,7 @@ GM_addStyle(` @keyframes colorPulse { 0% { color: #ff3333; } /* Start Red */ - 50% { color: #ffffff; } /* Midpoint Orange */ + 50% { color: #ffffff; } /* Midpoint White */ 100% { color: #ff3333; } /* End Red */ } @@ -34,6 +34,15 @@ } `); + // Get destination + const destination = document.querySelector("body").getAttribute("data-country"); + const destShortCode = destination.substring(0,3); + console.log(`Destination detected: ${destination}. Short Code: ${destShortCode}`); + /* TODO: Fix the table issue in getForeignStock + if (destination != "torn"){ + getForeignStock(destShortCode); + } + */ // Setup Formatter const currencyFormatter = new Intl.NumberFormat('en-US', { style: 'currency', @@ -41,9 +50,6 @@ maximumFractionDigits: 0, }); - //const flight_image = document.querySelector("#travel-root > div.viewport___cdEK9 > div.airspaceScene___euCKY.outboundFlight___rIvIA"); - //flight_image.remove(); - // 1. Wait for Torn's travel container to load const checkFlight = setInterval(() => { // Torn uses countdown timers inside specific structural classes depending on the layout type @@ -95,7 +101,36 @@ iteminfo.forEach(item => { getPriceInfo(item.id); }); + } + // Update the landing time prediction every single second + setInterval(() => { + const timeString = timerElement.innerText; // Grabs 'HH:MM:SS' from the page + if (!timeString) return; + + const timeParts = timeString.split(":"); + if (timeParts.length === 3) { + const hours = parseInt(timeParts[0], 10); + const minutes = parseInt(timeParts[1], 10); + const seconds = parseInt(timeParts[2], 10); + + // Convert countdown duration entirely to total milliseconds + const msRemaining = (hours * 60 * 60 + minutes * 60 + seconds) * 1000; + // Blink the text if time left is < 2 minutes. + if (msRemaining <= 120000) { + // Add the blinking class to the text. + timerContainer.classList.add("pulse-text"); + } + + // Add the flight duration to the current system date/time + const landingTime = new Date(Date.now() + msRemaining); + + // Format the output neatly (e.g., "16:24:05") + timerContainer.innerText = `Landing in ${destination.charAt(0).toUpperCase() + destination.slice(1)} at ${landingTime.toLocaleTimeString()}`; + } + }, 1000); + + } // Function to update the page with price info function updatePriceInfo() { var values = { @@ -131,6 +166,48 @@ //appraisePanel.innerText = `Quick Sell: ${values.bazaar_min} | Market: ${values.market} | Bazaar Avg: ${values.bazaar_average}`; } + function updateForeignStock(stockInfo) { + const progressContainer = document.querySelector('[class^="flightProgressSection"]'); + const infoContainer = document.createElement("div"); + let infoTable = document.createElement("table"); + //infoContainer.append(infoTable); + let tableHeader = document.createElement("tr"); + tableHeader.append(document) + tableHeader.createElement("th").innerText = "Item"; + tableHeader.createElement("th").innerText = "Quantity"; + tableHeader.createElement("th").innerText = "Price"; + stockInfo.stocks.forEach(item => { + let newRow = infoTable.createElement("tr"); + + newRow.createElement("td").innerText = `${item.name}`; + newRow.createElement("td").innerText = `${item.quantity}`; + newRow.createElement("td").innerText = `${currencyFormatter.format(item.cost)}`; + //let infoContainer = document.createElement("span"); + //infoContainer.innerText = `${item.name} | ${item.quantity} | ${item.cost}`; + progressContainer.parentNode.insertBefore(infoContainer, progressContainer.nextSibling); + }) + } + + // Get YATA Foreign stock information + function getForeignStock(country) { + var stockInfo = {}; + GM_xmlhttpRequest({ + method: "GET", + url: "https://yata.yt/api/v1/travel/export/", + //headers: {"Content-Type": "application/json" }, + onload: function(response) { + if (response.status === 200) { + var data = JSON.parse(response.responseText); + stockInfo = data.stocks[country]; + updateForeignStock(stockInfo); + //console.log(stockInfo); + } else { + console.log(`YATA Error ${response.status} - ${response.responseText}`); + } + } + }); + return stockInfo; + } // Function to get price information function getPriceInfo(itemId) { const w3bPriceUrl = "https://weav3r.dev/api/marketplace/" + itemId; // API Endpoint for W3B Market Information @@ -154,32 +231,5 @@ } }); } - // Update the landing time prediction every single second - setInterval(() => { - const timeString = timerElement.innerText; // Grabs 'HH:MM:SS' from the page - if (!timeString) return; - const timeParts = timeString.split(":"); - if (timeParts.length === 3) { - const hours = parseInt(timeParts[0], 10); - const minutes = parseInt(timeParts[1], 10); - const seconds = parseInt(timeParts[2], 10); - - // Convert countdown duration entirely to total milliseconds - const msRemaining = (hours * 60 * 60 + minutes * 60 + seconds) * 1000; - // Blink the text if time left is < 2 minutes. - if (msRemaining <= 120000) { - // Add the blinking class to the text. - timerContainer.classList.add("pulse-text"); - } - - // Add the flight duration to the current system date/time - const landingTime = new Date(Date.now() + msRemaining); - - // Format the output neatly (e.g., "16:24:05") - timerContainer.innerText = `Estimated Landing: ${landingTime.toLocaleTimeString()}`; - } - }, 1000); - - } })(); \ No newline at end of file