File size: 1,866 Bytes
484d45a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
document.addEventListener('DOMContentLoaded', function() {
    // Initialize countdown timer example
    const countdownEnd = new Date();
    countdownEnd.setHours(countdownEnd.getHours() + 24);
    
    startCountdown(countdownEnd.getTime());
    
    // Copy to clipboard functionality for code snippets
    document.querySelectorAll('pre').forEach(pre => {
        const button = document.createElement('button');
        button.className = 'copy-btn absolute top-2 right-2 bg-gray-200 hover:bg-gray-300 text-gray-800 text-xs px-2 py-1 rounded';
        button.innerHTML = '<i data-feather="copy" class="w-3 h-3"></i> Copy';
        button.onclick = () => {
            navigator.clipboard.writeText(pre.textContent);
            button.innerHTML = '<i data-feather="check" class="w-3 h-3"></i> Copied!';
            setTimeout(() => {
                button.innerHTML = '<i data-feather="copy" class="w-3 h-3"></i> Copy';
                feather.replace();
            }, 2000);
        };
        pre.style.position = 'relative';
        pre.appendChild(button);
    });
    
    feather.replace();
});

function startCountdown(endTime) {
    const timer = setInterval(() => {
        const now = new Date().getTime();
        const distance = endTime - now;
        
        const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
        const seconds = Math.floor((distance % (1000 * 60)) / 1000);
        
        const countdownEl = document.getElementById("countdown");
        if (countdownEl) {
            countdownEl.innerHTML = `${hours}h ${minutes}m ${seconds}s`;
            
            if (distance < 0) {
                clearInterval(timer);
                countdownEl.innerHTML = "OFFER EXPIRED";
            }
        }
    }, 1000);
}