async function updatePIPrice() { try { const response = await fetch('cron/pi_price.txt?' + new Date().getTime()); // Prevent caching if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); if (data.price) { const currentPrice = Number(data.price); const investment = 10; // $10 investment const piAmount = investment / currentPrice; // Update all price displays document.querySelectorAll('.pi-price').forEach(element => { element.textContent = `$${currentPrice.toFixed(6)}`; }); // Update PI amount document.querySelectorAll('.pi-amount').forEach(element => { element.textContent = `${Math.floor(piAmount)} PI`; }); // Update milestone calculations const milestone1 = (piAmount * 1).toLocaleString('en-US', { style: 'currency', currency: 'USD' }); document.querySelector('.milestone-1').textContent = milestone1; const milestone2 = (piAmount * 10).toLocaleString('en-US', { style: 'currency', currency: 'USD' }); document.querySelector('.milestone-2').textContent = milestone2; const milestone3 = (piAmount * 385).toLocaleString('en-US', { style: 'currency', currency: 'USD' }); document.querySelector('.milestone-3').textContent = milestone3; } } catch (error) { console.error('Error updating price:', error); // Only set fallback price if element is empty const priceElement = document.querySelector('.pi-price'); if (priceElement && !priceElement.textContent) { priceElement.textContent = '$0.001750'; } } } // Initial update immediately when DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', updatePIPrice); } else { updatePIPrice(); } // Check for updates every second setInterval(updatePIPrice, 1000);