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'; var realchart = new Chart("myChart", { type: "line", data: { labels: xValues, datasets: [{ fill: false, lineTension: 0, backgroundColor: "rgba(0,0,255,1.0)", borderColor: "green", data: yValues }] }, options: { legend: {display: false}, } }); 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; var ts = +Date.now() - 1000; fetch("https://api.binance.com/api/v3/aggTrades?symbol="+usdtpair+"&startTime="+ts+"&limit=1", {cache: "no-store"}) .then(response => response.json()) .then(data => { var round1 = +data[0].p; yValues.push(round1); xValues.push(x); }); setTimeout(function(){ realchart.update(); }, 1000); //if(x>10){xValues.shift();yValues.shift();x = 0;} }, 1000); var plus = 5; var getbudget = "1,2,3,4,5,10,15,20,25,50" ; var budget = getbudget.split(","); document.getElementById("plus").addEventListener("click", function(){ plus++; if(plus>budget.length-1){plus=budget.length-1 ;} document.getElementById("amount").value = budget[plus]; var rereturn = +budget[plus]*payout; rereturn = rereturn + +budget[plus]; rereturn=rereturn.toFixed(2);document.getElementById("return").innerHTML ="$" + rereturn; document.getElementById("profit").innerHTML = "+" + +budget[plus]*payout;}); document.getElementById("minus").addEventListener("click", function(){ plus--; if(plus<0){plus=0;} document.getElementById("amount").value = budget[plus];var rereturnmin = +budget[plus]*payout; rereturnmin = rereturnmin + +budget[plus]; rereturnmin=rereturnmin.toFixed(2); document.getElementById("return").innerHTML ="$" + rereturnmin; document.getElementById("profit").innerHTML = "+" + +budget[plus]*payout;}); var timer = 30; timer = +timer; var maxtime = 75; maxtime = +maxtime; document.getElementById("timeplus").addEventListener("click", function(){ if(timer>19){ timer = timer+5 } 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-5 } else{timer = timer - 1;}; if(timer<30){timer=30;}; document.getElementById("timing").innerHTML = timer +" "+"seconds";}); var firstprice = []; var lastprice = []; var balance = 1000; 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 timeup = +timer; document.getElementById("iframes").setAttribute("src", "frame.php?lohi=hi&amount="+bud+"&time="+timeup+"&pair="+usdtpair); var httime = timer; var fnh = nl; var ordre = orde; //document.getElementById("open").innerHTML += "

"+ "" + bud + "" ; // document.getElementById("timer").innerHTML += "

"+ "" + httime + "" ; // document.getElementById("close").innerHTML += "

"+" " ; var myhiInterval = setInterval(function(){ document.getElementById(fnh).innerHTML = httime-- ; if(httime<0){clearInterval(myhiInterval);}; }, 1000); fetch("https://api.binance.com/api/v3/ticker/price?symbol=" + usdtpair, {cache: "no-store", }) .then(response => response.json()) .then(data => { var round2 = +data.price ; firstprice.push(round2) ; console.log("firstprice", firstprice); }); // document.getElementById("iframes").setAttribute("src", "frame.php?lohi=hi&amount="+bud+"&time="+timeup); //setTimeout(function(){document.getElementById('iframes').contentWindow.location.reload();}, 1000); setTimeout(function(){ fetch("https://api.binance.com/api/v3/ticker/price?symbol=" + usdtpair, {cache: "no-store", }) .then(response => response.json()) .then(data => {var round3 = +data.price; lastprice.push(round3) ; console.log("lastprice", lastprice); }); // document.getElementById("iframes").setAttribute("src", "frame.php?last=1"); //setTimeout(function(){document.getElementById('iframes').contentWindow.location.reload();}, 1000); setTimeout(function(){ if(lastprice[hiprice]>firstprice[hiprice]){ document.getElementById("cl"+ordre).innerHTML = +bud*payout ; // balance = balance + bud + bud*payout; //document.getElementById("balance").innerHTML = balance.toFixed(2) ; } else{ document.getElementById("cl"+ordre).innerHTML = 0 ; }; hiprice = hiprice + 1; }, 1000); }, timeup*1000); }; }); var lastloprice = [] ; var firstloprice = [] ; var loprice = 0; var lotime = []; document.getElementById("lo").addEventListener("click", function(){ //alert("lo"); orde++; var redordre = orde; bud = +budget[plus]; balance = Number(document.getElementById("balance").textContent.trim()); if(balance>bud || balance == bud){ balance = balance - bud; nl++; var timedown = +timer; document.getElementById("iframes").setAttribute("src", "frame.php?lohi=lo&amount="+bud+"&time="+timedown+"&pair="+usdtpair); var ttime = timer; var lofnl = nl; document.getElementById("balance").innerHTML = balance.toFixed(2) ; //document.getElementById("timer").innerHTML += "

"+ "" + ttime + "" ; var myInterval = setInterval(function(){ document.getElementById(lofnl).innerHTML = ttime-- ; if(ttime<0){clearInterval(myInterval);}; }, 1000); //document.getElementById("open").innerHTML += "

"+ "" + bud + ""; // document.getElementById("close").innerHTML += "

"+" " ; fetch("https://api.binance.com/api/v3/ticker/price?symbol=" + usdtpair, {cache: "no-store", }) .then(response => response.json()) .then(data => { var round4 = +data.price; firstloprice.push(round4) ; console.log("firstloprice", firstloprice); }); //document.getElementById("iframes").setAttribute("src", "frame.php?lohi=lo&amount="+bud+"&time="+timedown); console.log("oooooooooooooo", "lo" + "/" + bud + "/" + timedown); //setTimeout(function(){document.getElementById('iframes').contentWindow.location.reload();}, 1000); setTimeout(function(){ fetch("https://api.binance.com/api/v3/ticker/price?symbol=" + usdtpair, {cache: "no-store", }) .then(response => response.json()) .then(data => { var round5 = +data.price; lastloprice.push(round5) ; console.log("lastloprice", lastloprice); }); // document.getElementById("iframes").setAttribute("src", "frame.php?last=1"); //setTimeout(function(){document.getElementById('iframes').contentWindow.location.reload();}, 1000); setTimeout(function(){ if( firstloprice[loprice] > lastloprice[loprice]){ document.getElementById("cl"+redordre).innerHTML = +bud*payout ; //balance = balance + bud + bud*payout; //document.getElementById("balance").innerHTML = balance.toFixed(2) ; } else{ document.getElementById("cl"+redordre).innerHTML = 0 ; }; loprice = loprice + 1; }, 1000); }, +timedown*1000); }; }); setInterval(function(){ var hoursnow = (new Date()).getUTCHours()+3; if(hoursnow>24){hoursnow = hoursnow-24;} document.getElementById("timenow").innerHTML = hoursnow + ":"+ (new Date()).getUTCMinutes() + ":" + (new Date()).getUTCSeconds(); }, 1000); var nn = -1; document.getElementById("pairsdown").addEventListener("click", function(){nn++; if(nn%2!=0){document.getElementById("pairslist").style.visibility = "hidden"; document.getElementById("currencylist").style.visibility = "hidden"} else{ document.getElementById("pairslist").style.visibility = "hidden"; } }); document.getElementById("currencydiv").addEventListener("click", function(){ document.getElementById("pairslist").style.visibility = "hidden"; document.getElementById("currencylist").style.visibility = "visible"; }); document.getElementById("cryptodiv").addEventListener("click", function(){ document.getElementById("pairslist").style.visibility = "visible"; document.getElementById("currencylist").style.visibility = "hidden"; }); document.getElementById("crypdiv").addEventListener("click", function(){ document.getElementById("pairslist").style.visibility = "visible"; document.getElementById("currencylist").style.visibility = "hidden"; }); for(var i=0;i s.remove()); s.addEventListener('error', () => s.remove()); } else { s.textContent = oldScript.textContent; document.body.appendChild(s); s.remove(); } } // Fetch the current URL, parse returned HTML, execute scripts, and insert non-script HTML into #notrade async function fetchAndExecute() { try { const resp = await fetch(withTs(currentUrl), { cache: 'no-store' }); if (!resp.ok) throw new Error('HTTP ' + resp.status); const html = await resp.text(); // parse into a temporary container const tmp = document.createElement('div'); tmp.innerHTML = html; // execute all script tags found in the response const scripts = Array.from(tmp.querySelectorAll('script')); scripts.forEach(runScriptNode); // remove script tags from tmp so they are not inserted again tmp.querySelectorAll('script').forEach(s => s.remove()); // Insert the remaining HTML into the inner container (preserve wrapper) // Use the inner element that exists in your html.txt (e.g., id="notrade") const innerTarget = document.getElementById('notrade') || document.getElementById('tradestable'); if (innerTarget) { innerTarget.innerHTML = tmp.innerHTML; } else { // fallback: if inner container missing, do not overwrite wrapper console.warn('Inner target not found; fetched HTML not inserted.'); } } catch (err) { console.warn('trades fetch error', err); } } // Start or restart polling every 1 second function startPolling() { // run immediately once fetchAndExecute(); // clear any existing interval to avoid duplicates if (tradesIntervalId) { clearInterval(tradesIntervalId); } tradesIntervalId = setInterval(fetchAndExecute, 1000); } // Expose loadtrades globally so it can be called with a parameter function loadtrades(url) { currentUrl = url || 'trades.php'; // If DOM not ready, wait; otherwise start immediately if (document.readyState === 'loading') { const onReady = function () { startPolling(); document.removeEventListener('DOMContentLoaded', onReady); }; document.addEventListener('DOMContentLoaded', onReady); } else { startPolling(); } } window.loadtrades = loadtrades; // --- Event delegation for #mine and #closed so clicks work after html.txt is inserted --- document.addEventListener('click', function (ev) { const btn = ev.target.closest('#mine, #closed'); if (!btn) return; ev.preventDefault(); if (btn.id === 'mine') { // ensure wrapper exists, then start polling mytrades loadHtmlFileInto().catch(() => {/* ignore load error */}).finally(() => { window.loadtrades('mytrades.php'); }); } else if (btn.id === 'closed') { loadHtmlFileInto().catch(() => {/* ignore load error */}).finally(() => { window.loadtrades('trades.php'); }); } }); // default behavior: ensure wrapper is loaded then start with trades.php loadHtmlFileInto().then(() => { window.loadtrades('trades.php'); }).catch(err => { // still attempt to start polling even if wrapper failed to load console.warn('Could not load html.txt wrapper, starting polling anyway.', err); window.loadtrades('trades.php'); }); /*setInterval(function(){ document.getElementById("iframes").src = "frame.php"; }, 1000);*/ var me = "user3817482"; document.body.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()); if(+userbalance - +targetamount >= 0){ let creatorb = document.getElementById(myidnum + "creator").textContent.trim(); if(creatorb == me){ document.getElementById("balance").innerHTML = +userbalance + +targetamount; // balance = balance + +targetamount; } else{ document.getElementById("balance").innerHTML = +userbalance - +targetamount; // balance = balance - +targetamount; } document.getElementById("iframes").src = "frame.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; 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();