// Mining simulation logic let miningInterval; let minedAmount = 0; let miningPower = 1; // Default mining power let isMining = false; function initMiningSimulation() { // Load saved data if exists const savedData = localStorage.getItem('pocketMinerData'); if (savedData) { const data = JSON.parse(savedData); minedAmount = data.minedAmount || 0; miningPower = data.miningPower || 1; updateMiningStats(); } } function startMining() { if (isMining) return; isMining = true; document.getElementById('miningStatus').classList.add('mining-active'); document.getElementById('startMiningBtn').classList.add('hidden'); document.getElementById('stopMiningBtn').classList.remove('hidden'); miningInterval = setInterval(() => { // Simulate mining with random variance const variance = 0.8 + Math.random() * 0.4; // 0.8-1.2 multiplier minedAmount += (0.000001 * miningPower * variance); updateMiningStats(); saveToLocalStorage(); }, 1000); } function stopMining() { isMining = false; clearInterval(miningInterval); document.getElementById('miningStatus').classList.remove('mining-active'); document.getElementById('startMiningBtn').classList.remove('hidden'); document.getElementById('stopMiningBtn').classList.add('hidden'); saveToLocalStorage(); } function updateMiningStats() { document.getElementById('minedAmount').textContent = minedAmount.toFixed(8); document.getElementById('miningPowerValue').textContent = miningPower.toFixed(2); document.getElementById('walletBalance').textContent = minedAmount.toFixed(8); } function upgradeMiningPower() { const cost = miningPower * 0.0001; if (minedAmount >= cost) { minedAmount -= cost; miningPower += 0.25; updateMiningStats(); saveToLocalStorage(); // Show upgrade notification showNotification('Mining power upgraded to ' + miningPower.toFixed(2) + ' TH/s!'); } else { showNotification('Not enough BTC to upgrade mining power!', 'error'); } } function withdrawToWallet() { if (minedAmount > 0.00005) { // Minimum withdrawal amount showNotification(`${minedAmount.toFixed(8)} BTC withdrawn to your wallet!`, 'success'); minedAmount = 0; updateMiningStats(); saveToLocalStorage(); } else { showNotification('Minimum withdrawal amount is 0.00005 BTC', 'error'); } } function showNotification(message, type = 'info') { const notification = document.createElement('div'); notification.className = `fixed top-4 right-4 px-4 py-2 rounded-md shadow-lg text-white ${ type === 'error' ? 'bg-red-500' : type === 'success' ? 'bg-green-500' : 'bg-blue-500' }`; notification.textContent = message; document.body.appendChild(notification); setTimeout(() => { notification.classList.add('opacity-0', 'transition-opacity', 'duration-300'); setTimeout(() => notification.remove(), 300); }, 3000); } function saveToLocalStorage() { localStorage.setItem('pocketMinerData', JSON.stringify({ minedAmount, miningPower })); } // Navigation function function navigateTo(page) { window.location.href = page; }