// Global variables let currentMarketData = {}; // Translation helper for JS const translations = { 'en': { 'Buy': 'Buy', 'Sell': 'Sell', 'Trade': 'Trade', 'Price': 'Price', 'Amount': 'Amount' }, 'zh': { 'Buy': '买入', 'Sell': '卖出', 'Trade': '交易', 'Price': '价格', 'Amount': '数量' }, // ... add more as needed or fetch from server }; function getLang() { return document.documentElement.lang || 'en'; } function tj(key) { const lang = getLang(); return (translations[lang] && translations[lang][key]) || key; } // Market Data Fetching async function fetchMarketData() { try { const resp = await fetch('api/market_api.php'); const result = await resp.json(); if (result.success) { currentMarketData = result.data; updateUI(); } } catch (e) { console.error('Market API error', e); } } function updateUI() { // Update Trade Page if on it if (document.getElementById('crypto-list-container')) { updateTradePage(); } // Update Market Page if on it if (document.getElementById('all-market-body')) { updateMarketPage(); } } function updateTradePage() { const listContainer = document.getElementById('crypto-list-container'); const search = document.getElementById('market-search')?.value.toLowerCase() || ''; const currentSymbol = document.getElementById('current-symbol')?.value; let html = ''; Object.keys(currentMarketData).forEach(symbol => { if (symbol.toLowerCase().includes(search) || currentMarketData[symbol].name.toLowerCase().includes(search)) { const coin = currentMarketData[symbol]; const active = symbol === currentSymbol ? 'active' : ''; const changeClass = coin.change >= 0 ? 'text-success' : 'text-danger'; const changeSign = coin.change >= 0 ? '+' : ''; html += `