| 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); | |
| } |