`; return timerDiv; } // Function to check if the target element exists function waitForElements(selector, callback) { const elements = document.querySelectorAll(selector); if (elements.length > 0) { callback(elements); } else { setTimeout(() => waitForElements(selector, callback), 500); // Retry every 500ms } } // Wait for the target elements to exist, then insert the countdown timer into the first one only waitForElements('#news .prd-recomd-card.widest', function(targetElements) { if (targetElements.length > 0) { const firstTargetElement = targetElements[0]; // Get the first element const timerDiv = createCountdownTimer(); // Create the countdown for the first element firstTargetElement.insertBefore(timerDiv, firstTargetElement.firstChild); // Start countdown once the timer has been added to the DOM function updateCountdown() { const daysElement = timerDiv.querySelector("#days"); const hoursElement = timerDiv.querySelector("#hours"); const minutesElement = timerDiv.querySelector("#minutes"); const secondsElement = timerDiv.querySelector("#seconds"); if (!daysElement || !hoursElement || !minutesElement || !secondsElement) { return; } // Set the target countdown date to 27 October 23:59 const countDownDate = new Date('2025-04-13T23:59:59').getTime(); const now = new Date().getTime(); const diff = countDownDate - now; if (diff > 0) { let days = Math.floor(diff / (1000 * 60 * 60 * 24)); let hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); let minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); let seconds = Math.floor((diff % (1000 * 60)) / 1000); daysElement.textContent = days.toString().padStart(2, '0'); hoursElement.textContent = hours.toString().padStart(2, '0'); minutesElement.textContent = minutes.toString().padStart(2, '0'); secondsElement.textContent = seconds.toString().padStart(2, '0'); timerDiv.style.display = "block"; } else { timerDiv.style.display = "none"; // Hide the countdown if the target time has passed } } setInterval(updateCountdown, 1000); } });
Opuszczasz stronę consumer.huawei.com
Po kliknięciu w link zostaniesz przeniesiony na zewnętrzną stronę. Firma Huawei nie jest odpowiedzialna za strony zewnętrzne oraz nie ich kontroluje.
Powrót Kontynuuj