var usdtpair = 'BTCUSDT'; (function(){ // All DOM queries are scoped to the root container to avoid touching other page elements. const root = document.getElementById('usdt-selector-root'); if (!root) return; const openBtn = root.querySelector('#usdt-openAll'); const list = root.querySelector('#usdt-list'); const card = root.querySelector('#usdt-card'); const selectedEl = root.querySelector('#usdt-selected'); function markSelected(pairEl){ root.querySelectorAll('.pair').forEach(p => { p.style.outline = ''; p.classList.remove('is-selected'); }); if (!pairEl) return; pairEl.style.outline = '2px solid rgba(155,124,255,0.18)'; pairEl.classList.add('is-selected'); const sym = pairEl.querySelector('.sym'); // Use Unicode bullet to avoid encoding issues selectedEl.textContent = (sym ? sym.textContent : pairEl.dataset.pair) + ' \u2022 ' + pairEl.dataset.pair; } // Initialize: keep list closed and select default function init(){ if (!list || !openBtn) return; list.classList.remove('open'); list.style.maxHeight = '0'; list.setAttribute('aria-hidden','true'); openBtn.textContent = 'Show Pairs'; openBtn.setAttribute('aria-expanded','false'); const defaultPair = root.querySelector('.pair[data-pair="BTCUSDT"]'); if (defaultPair) { markSelected(defaultPair); const details = defaultPair.closest('details'); if (details) details.open = true; } } // Toggle open/close if (openBtn && list) { openBtn.addEventListener('click', () => { const isOpen = list.classList.toggle('open'); openBtn.textContent = isOpen ? 'Hide Pairs' : 'Show Pairs'; openBtn.setAttribute('aria-expanded', String(isOpen)); list.setAttribute('aria-hidden', String(!isOpen)); if (isOpen) { list.style.maxHeight = Math.round(window.innerHeight * 0.6) + 'px'; const sel = root.querySelector('.pair.is-selected'); if (sel) sel.scrollIntoView({ behavior: 'smooth', block: 'center' }); } else { list.style.maxHeight = '0'; } }); } // Keep height responsive while open window.addEventListener('resize', () => { if (list && list.classList.contains('open')) { list.style.maxHeight = Math.round(window.innerHeight * 0.6) + 'px'; } }); // Delegated click handler scoped to the card if (card) { card.addEventListener('click', (e) => { const pairEl = e.target.closest('.pair'); if (!pairEl || !card.contains(pairEl)) return; markSelected(pairEl); // Dispatch a scoped custom event on the root so host page can listen if desired root.dispatchEvent(new CustomEvent('usdt:pair-selected', { detail: { pair: pairEl.dataset.pair } })); usdtpair = pairEl.dataset.pair; }); // Keyboard accessibility: Enter/Space selects card.addEventListener('keydown', (e) => { const el = e.target.closest('.pair'); if (!el || !card.contains(el)) return; if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); el.click(); } }); } // Run init after DOM is ready for this block if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })(); var payout = "0.20"; payout = 1 - +payout; var xValues = []; var yValues = []; var x = 0; var oldpair = 'BTCUSDT'; const realchart = new Chart("myChart", { type: "line", data: { labels: xValues, datasets: [{ label: '', // no label text next to a color box fill: false, pointRadius: 0, // hide point marker pointHoverRadius: 0, // hide hover marker backgroundColor: "rgba(0,0,255,1.0)", borderColor: "green", data: yValues }] }, options: { spanGaps: true, plugins: { legend: { display: false, labels: { boxWidth: 0 } // extra safety for legend color box }, tooltip: { displayColors: false, // remove the small colored square in tooltip callbacks: { title: () => '', // optional: hide tooltip title label: ctx => { const v = ctx.raw; return (v === null || v === undefined) ? '' : v.toString(); } } } }, interaction: { intersect: true }, hover: { mode: 'nearest' } } }); window.realchart = realchart; setInterval(function(){ if (oldpair !== usdtpair && window.realchart) { x = 0; xValues.length = 0; yValues.length = 0; realchart.data.labels = xValues; realchart.data.datasets[0].data = yValues; realchart.update(); oldpair = usdtpair; } x = x + 1; const ts = Date.now() - 1000; const url = "https://api.binance.com/api/v3/aggTrades?symbol=" + usdtpair + "&startTime=" + ts + "&limit=1"; fetch(url, { cache: "no-store" }) .then(r => r.json()) .then(data => { // debug: uncomment to inspect API shape // console.log('api data', data); if (!Array.isArray(data) || data.length === 0 || !data[0] || data[0].p == null) { // no valid price this tick — skip updating the chart return; } const round1 = parseFloat(data[0].p); if (Number.isNaN(round1)) { return; } yValues.push(round1); xValues.push(x); // keep chart arrays in sync and update only after valid push realchart.data.labels = xValues; realchart.data.datasets[0].data = yValues; realchart.update(); }) .catch(err => { console.error('fetch error', err); }); // DO NOT call realchart.update() here }, 1000); var plus = 0; var getbudget = "0.01,0.1,0.10,1,10,100,1000" ; var budget = getbudget.split(","); var initialreturn = budget[plus]; var initialprofit = budget[plus]*payout; document.getElementById('amount').setAttribute("min", budget[1]); document.getElementById('amount').setAttribute("max", budget[budget.length-1]); document.getElementById("amount").value = budget[0]; initialreturn = Number(initialreturn) + Number(initialprofit); document.getElementById("return").innerHTML ="$" + initialreturn.toFixed(4); document.getElementById("profit").innerHTML = "+" + initialprofit.toFixed(4); document.getElementById("plus").addEventListener("click", function(){ plus++; if(plus>budget.length-1){plus=budget.length-1 ;} if(+plus<+budget.length && +plus>0){document.getElementById('amount').setAttribute("min", budget[plus-1]); document.getElementById('amount').setAttribute("step", +budget[+plus] / 10);} document.getElementById("amount").value = budget[plus]; var rereturn = +budget[plus]*payout; rereturn = rereturn + +budget[plus];document.getElementById("return").innerHTML ="$" + rereturn.toFixed(4); document.getElementById("profit").innerHTML = "+" + (+budget[plus]*payout).toFixed(4);}); document.getElementById("minus").addEventListener("click", function(){ plus--; if(plus<0){plus=0;} if(+plus<+budget.length && +plus>0){document.getElementById('amount').setAttribute("min", budget[plus-1]); document.getElementById('amount').setAttribute("step", +budget[+plus] / 10);} document.getElementById("amount").value = budget[plus];var rereturnmin = +budget[plus]*payout; rereturnmin = rereturnmin + +budget[plus]; document.getElementById("return").innerHTML ="$" + rereturnmin.toFixed(4); document.getElementById("profit").innerHTML = "+" + (+budget[plus]*payout).toFixed(4);}); document.getElementById("amount").addEventListener('change', function(){ var initialprofit1 = +document.getElementById("amount").value * payout; var initialreturn1 = +document.getElementById("amount").value + initialprofit1; document.getElementById("return").innerHTML ="$" + initialreturn1.toFixed(4); document.getElementById("profit").innerHTML = "+" + initialprofit1.toFixed(4); }); var timer = 30; timer = +timer; var maxtime = 75; var timerange = 5; maxtime = +maxtime; document.getElementById("timeplus").addEventListener("click", function(){ if(timer>19){ timer = timer+timerange } else{timer = timer + 1;}; if(timer>maxtime){timer=maxtime;};document.getElementById("timing").innerHTML = timer +" " + "seconds";}); document.getElementById("timeminus").addEventListener("click", function(){ if(timer>24){ timer = timer-timerange } else{timer = timer - 1;}; if(timer<30){timer=30;}; document.getElementById("timing").innerHTML = timer +" "+"seconds";}); var firstprice = []; var lastprice = []; var balance = 1000; document.getElementById('balance').innerHTML = balance.toFixed(2); var hiprice = 0; var bud = +budget[plus]; var nl = 0; var orde = 0; document.getElementById("hi").addEventListener("click", function(){ //alert("Hi"); orde++; bud = +budget[plus]; balance = Number(document.getElementById("balance").textContent.trim()); if(balance>bud || balance == bud){ nl++; // balance = balance - bud; // document.getElementById("balance").innerHTML = balance.toFixed(2) ; var inputamount = document.getElementById('amount').value; var timeup = +timer; document.getElementById("acceptor").setAttribute("src", "acceptor.php?lohi=hi&amount="+inputamount+"&time="+timeup+"&pair="+usdtpair); }; }); var me = "user3388429"; window.addEventListener("click", function (event) { let myid = event.target.id || ""; let elemid = document.getElementById(myid); let myidnum = 0; let userbalance = 0; let targetamount = 0; if(me && me != 1 && myid.includes("actionBtn") ){ myidnum = parseInt(myid, 10); let timertarget = Number(document.getElementById(myidnum + "timer").textContent.trim()); if(+timertarget > 0){ userbalance = Number(document.getElementById("balance").textContent.trim()); targetamount = Number(document.getElementById(myidnum + "amount").textContent.trim()); let creatorb = document.getElementById(myidnum + "creator").textContent.trim(); if(creatorb == me){ // document.getElementById("balance").innerHTML = +userbalance + +targetamount; // balance = balance + +targetamount; document.getElementById("acceptor").src = "acceptor.php?acceptor=" + me + "&rowid=" + myidnum +"&pair="+usdtpair; } else if(+userbalance - +targetamount >= 0 && creatorb != me){ // document.getElementById("balance").innerHTML = +userbalance - +targetamount; // balance = balance - +targetamount; document.getElementById("acceptor").src = "acceptor.php?acceptor=" + me + "&rowid=" + myidnum +"&pair="+usdtpair; } //userbalance = 0; //targetamount = 0; elemid.style.visibility = "hidden"; //elemid.disabled = true; //elemid.style.opacity = "0.85"; } }; }); function updateBalance() { fetch('/balance.php', { cache: 'no-store' }) .then(response => response.json()) .then(data => { const addme = data.toadd; const balanceEl = document.getElementById("balance"); const currentBalance = Number(balanceEl.textContent.trim()); const newBalance = currentBalance + Number(addme); balanceEl.innerHTML = newBalance.toFixed(2); console.log("toadd", addme); // Schedule the next run AFTER this one finishes setTimeout(updateBalance, 1000); }) .catch(err => { console.error('Fetch error:', err); // Retry after delay even if error setTimeout(updateBalance, 1000); }); } // Start the loop updateBalance(); function updateSchedule() { fetch('/frame.php', { cache: 'no-store' }) .then(response => response.json()) .then(data => { const jobbie = data.myjob; if(jobbie == "work-done"){ // Schedule the next run AFTER this one finishes setTimeout(updateSchedule, 1000); } }) .catch(err => { console.error('Fetch error:', err); // Retry after delay even if error setTimeout(updateSchedule, 1000); }); } // Start the loop updateSchedule();