Spaces:
Running
Running
| document.addEventListener('DOMContentLoaded', function() { | |
| // Mining simulation variables | |
| let isMining = false; | |
| let miningInterval; | |
| let totalHashes = 0; | |
| let minedBTC = 0; | |
| let btcPrice = 42000; // Current BTC price in USD | |
| // DOM elements | |
| const toggleMiningBtn = document.getElementById('toggle-mining'); | |
| const miningStatus = document.getElementById('mining-status'); | |
| const hashRate = document.getElementById('hash-rate'); | |
| const hashProgress = document.getElementById('hash-progress'); | |
| const btcMined = document.getElementById('btc-mined'); | |
| const btcProgress = document.getElementById('btc-progress'); | |
| const powerUsage = document.getElementById('power-usage'); | |
| const temperature = document.getElementById('temperature'); | |
| const difficulty = document.getElementById('difficulty'); | |
| const estimatedEarnings = document.getElementById('estimated-earnings'); | |
| const last24h = document.getElementById('24h-mined'); | |
| const last7d = document.getElementById('7d-mined'); | |
| const allTime = document.getElementById('alltime-mined'); | |
| // Initialize with random difficulty | |
| updateDifficulty(); | |
| // Toggle mining button | |
| toggleMiningBtn.addEventListener('click', function() { | |
| isMining = !isMining; | |
| if (isMining) { | |
| startMining(); | |
| toggleMiningBtn.innerHTML = '<i data-feather="power"></i><span>Stop Mining</span>'; | |
| toggleMiningBtn.classList.remove('bg-primary'); | |
| toggleMiningBtn.classList.add('bg-red-500', 'hover:bg-red-600'); | |
| miningStatus.textContent = 'MINING'; | |
| miningStatus.classList.remove('bg-red-500'); | |
| miningStatus.classList.add('bg-green-500'); | |
| feather.replace(); | |
| } else { | |
| stopMining(); | |
| toggleMiningBtn.innerHTML = '<i data-feather="power"></i><span>Start Mining</span>'; | |
| toggleMiningBtn.classList.remove('bg-red-500', 'hover:bg-red-600'); | |
| toggleMiningBtn.classList.add('bg-primary'); | |
| miningStatus.textContent = 'OFFLINE'; | |
| miningStatus.classList.remove('bg-green-500'); | |
| miningStatus.classList.add('bg-red-500'); | |
| feather.replace(); | |
| } | |
| }); | |
| function startMining() { | |
| // Start mining simulation | |
| miningInterval = setInterval(function() { | |
| // Simulate hash rate between 90-110 TH/s | |
| const currentHashRate = 95 + Math.random() * 10; | |
| totalHashes += currentHashRate * 1000; | |
| // Simulate BTC mined (very small amounts) | |
| const hashProbability = 1 / (1000000000000); // Very small chance | |
| if (Math.random() < hashProbability) { | |
| const blockReward = 6.25; | |
| minedBTC += blockReward * (0.0001 + Math.random() * 0.0001); | |
| updateMiningStats(); | |
| } | |
| // Update UI | |
| hashRate.textContent = Math.round(currentHashRate * 100) / 100 + ' TH/s'; | |
| hashProgress.style.width = Math.min(100, (currentHashRate - 90) * 5) + '%'; | |
| btcMined.textContent = minedBTC.toFixed(8) + ' BTC'; | |
| btcProgress.style.width = Math.min(100, minedBTC * 1000000) + '%'; | |
| powerUsage.textContent = Math.round(3250 + Math.random() * 200) + ' W'; | |
| temperature.textContent = Math.round(65 + Math.random() * 10) + '°C'; | |
| // Randomly update difficulty sometimes | |
| if (Math.random() < 0.01) { | |
| updateDifficulty(); | |
| } | |
| // Update estimated earnings | |
| const dailyEarnings = currentHashRate * 0.0000001 * btcPrice * 24; | |
| estimatedEarnings.textContent = '$' + dailyEarnings.toFixed(2) + '/day'; | |
| }, 1000); | |
| } | |
| function stopMining() { | |
| clearInterval(miningInterval); | |
| hashRate.textContent = '0 H/s'; | |
| hashProgress.style.width = '0%'; | |
| powerUsage.textContent = '0 W'; | |
| temperature.textContent = '0°C'; | |
| } | |
| function updateDifficulty() { | |
| const newDifficulty = 25 + Math.random() * 5; | |
| difficulty.textContent = newDifficulty.toFixed(2) + ' T'; | |
| } | |
| function updateMiningStats() { | |
| last24h.textContent = (minedBTC * 0.3).toFixed(8) + ' BTC'; | |
| last7d.textContent = (minedBTC * 0.7).toFixed(8) + ' BTC'; | |
| allTime.textContent = minedBTC.toFixed(8) + ' BTC'; | |
| } | |
| // Simulate BTC price changes | |
| setInterval(function() { | |
| btcPrice = btcPrice * (0.998 + Math.random() * 0.004); | |
| }, 30000); | |
| }); |