Moved code around. Began YATA Foreign Stock Testing.

This commit is contained in:
2026-07-08 01:51:30 -04:00
parent 2c7977a715
commit bd7cfef2ee
+81 -31
View File
@@ -16,7 +16,7 @@
GM_addStyle(` GM_addStyle(`
@keyframes colorPulse { @keyframes colorPulse {
0% { color: #ff3333; } /* Start Red */ 0% { color: #ff3333; } /* Start Red */
50% { color: #ffffff; } /* Midpoint Orange */ 50% { color: #ffffff; } /* Midpoint White */
100% { color: #ff3333; } /* End Red */ 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 // Setup Formatter
const currencyFormatter = new Intl.NumberFormat('en-US', { const currencyFormatter = new Intl.NumberFormat('en-US', {
style: 'currency', style: 'currency',
@@ -41,9 +50,6 @@
maximumFractionDigits: 0, 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 // 1. Wait for Torn's travel container to load
const checkFlight = setInterval(() => { const checkFlight = setInterval(() => {
// Torn uses countdown timers inside specific structural classes depending on the layout type // Torn uses countdown timers inside specific structural classes depending on the layout type
@@ -95,6 +101,35 @@
iteminfo.forEach(item => { iteminfo.forEach(item => {
getPriceInfo(item.id); 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 to update the page with price info
function updatePriceInfo() { function updatePriceInfo() {
@@ -131,6 +166,48 @@
//appraisePanel.innerText = `Quick Sell: ${values.bazaar_min} | Market: ${values.market} | Bazaar Avg: ${values.bazaar_average}`; //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 to get price information
function getPriceInfo(itemId) { function getPriceInfo(itemId) {
const w3bPriceUrl = "https://weav3r.dev/api/marketplace/" + itemId; // API Endpoint for W3B Market Information 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);
}
})(); })();