PageSourceSearch

https://www.doorsopendays.org.uk/scripts/countdown-timer.js

js doorsopendays.org.uk collected 2026-10-02 03:59:57 UTC 2,083 bytes, 46 lines download raw bytes

1// Countdown timer.
2(function () {
3
4    // Get the countdown element with the js-countdownclock directive
5    var countdownElem = document.querySelector('[js-countdownclock]');
6
7    if (countdownElem) {
8        // Get the countdown date from the data attributes of the countdown element
9        var countdownDate = new Date(countdownElem.getAttribute('data-launchdate'));
10
11        function updateCountdown() {
12
13            // Get the current time
14            var now = new Date().getTime();
15            var distance = countdownDate.getTime() - now;
16            var days = Math.floor(distance / (1000 * 60 * 60 * 24));
17            var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
18            var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
19            var seconds = Math.floor((distance % (1000 * 60)) / 1000);
20
21            //When date is reached show the end message and hide the days, hours and minutes.
22            if (distance < 0) {
23
24                document.getElementById("timer-days").style.display = "none";
25                document.getElementById("timer-hours").style.display = "none";
26                document.getElementById("timer-minutes").style.display = "none";
27                document.getElementById("timer-seconds").style.display = "none";
28                document.getElementById("timer-complete").style.display = "flex";
29
30                clearInterval(interval);
31            }
32
33            // Display the result in the elements
34            document.getElementById("days").innerHTML = days;
35            document.getElementById("hours").innerHTML = hours;
36            document.getElementById("minutes").innerHTML = minutes;
37            document.getElementById("seconds").innerHTML = seconds;
38        }
39
40        // Call the function initially to avoid delay
41        updateCountdown();
42
43        // Update the countdown element every second, set it as a variable so we clear it once it hits zero.
44        const interval = setInterval(updateCountdown, 1000);
45    }
46})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.