const symbolMap = { 131: "XXX/TRY", 113: "USD/TRY", 114: "EUR/TRY", 115: "GBP/TRY", 116: "AUD/TRY", 117: "CAD/TRY", 118: "CHF/TRY", 121: "SAR/TRY", 123: "JPY/TRY", 235: "AED/TRY", 240: "QAR/TRY", 243: "SGD/TRY", }; let exchangeRates = {}; // Tüm kurları tutmak için boş bir obje function connect() { const socket = new WebSocket("wss://websocket.hakanaltin.com"); socket.onopen = () => { }; socket.onmessage = (event) => { try { const jsonData = JSON.parse(event.data); if (jsonData && jsonData.i && symbolMap[jsonData.i]) { // Gelen veriyi exchangeRates objesine kaydet const currencyCode = symbolMap[jsonData.i].split('/')[0].toLowerCase(); exchangeRates[currencyCode] = { buy: jsonData.b, }; // RUB verisini manuel ekle if (!exchangeRates.rub) { exchangeRates.rub = { buy: 1 }; // RUB verisini manuel olarak ayarladık } sendToPHP(exchangeRates); // Tüm verileri PHP'ye gönder } } catch (e) { } }; socket.onclose = () => { setTimeout(connect, 5000); // 5 saniye sonra yeniden bağlan }; socket.onerror = (error) => { socket.close(); }; } // PHP'ye tüm verileri AJAX ile gönderme function sendToPHP(data) { const xhr = new XMLHttpRequest(); xhr.open("POST", "https://www.sanlidoviz.com/kurlar", true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { try { const responseData = JSON.parse(xhr.responseText); updateDisplay(responseData.exchangeRates); // Gelen verileri ekranda göster } catch (e) { } } else { } } }; xhr.send(JSON.stringify(data)); } function updateDisplay(exchangeRates) { const currencies = ['xxx', 'usd', 'eur', 'gbp', 'rub', 'aud', 'cad', 'chf', 'sar', 'jpy', 'aed', 'qar', 'sgd']; currencies.forEach(currency => { const buyElement = document.getElementById(`${currency}-buy`); const sellElement = document.getElementById(`${currency}-sell`); const buyArrowElement = document.getElementById(`${currency}-buy-arrow`); const sellArrowElement = document.getElementById(`${currency}-sell-arrow`); if (exchangeRates[currency]) { const buyRate = parseFloat(exchangeRates[currency].buy); const sellRate = parseFloat(exchangeRates[currency].sell); if (buyElement && sellElement) { buyElement.innerHTML = buyRate.toFixed(4); sellElement.innerHTML = sellRate.toFixed(4); } const previousBuy = parseFloat(buyElement.getAttribute('data-prev-buy')) || buyRate; const previousSell = parseFloat(sellElement.getAttribute('data-prev-sell')) || sellRate; if (buyArrowElement && sellArrowElement) { // Buy Rate Logic if (buyRate > previousBuy) { buyArrowElement.querySelector('img').src = '../assets/img/up.png'; buyElement.classList.add('flash-green'); setTimeout(() => { buyElement.classList.remove('flash-green'); }, 500); } else if (buyRate < previousBuy) { buyArrowElement.querySelector('img').src = '../assets/img/down.png'; buyElement.classList.add('flash-red'); setTimeout(() => { buyElement.classList.remove('flash-red'); }, 500); } // Sell Rate Logic if (sellRate > previousSell) { sellArrowElement.querySelector('img').src = '../assets/img/up.png'; sellElement.classList.add('flash-green'); // Ensure you're using the correct element setTimeout(() => { sellElement.classList.remove('flash-green'); }, 500); } else if (sellRate < previousSell) { sellArrowElement.querySelector('img').src = '../assets/img/down.png'; sellElement.classList.add('flash-red'); // Ensure you're using the correct element setTimeout(() => { sellElement.classList.remove('flash-red'); }, 500); } } // Store the current rates as previous rates for comparison in the next update buyElement.setAttribute('data-prev-buy', buyRate); sellElement.setAttribute('data-prev-sell', sellRate); } }); const lastUpdateElement = document.getElementById('last-update'); if (lastUpdateElement) { const currentTime = new Date().toLocaleTimeString('tr-TR', { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false }); lastUpdateElement.innerHTML = `${currentTime}`; } } connect();