File size: 4,647 Bytes
bb29b88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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);
});