-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (62 loc) · 2.73 KB
/
index.js
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
// Set the date we're counting down to
var debugMode = window.location.search.includes('DEBUG');
var countDownDate = debugMode ? new Date().getTime() + 3000 : new Date("Mar 2, 2024 18:30:00").getTime();
// Function to update the countdown
function updateCountdown() {
// Get the current date and time
var now = new Date().getTime();
// Calculate the time remaining
var distance = countDownDate - now;
// Check if the countdown has reached 0 or less
if (distance <= 0) {
// Execute your function here
countdownReachedZero();
// Stop the countdown
clearInterval(x);
setCountdownToZero()
// Display a message or perform any other actions
console.log("EXPIRED");
return;
}
// Calculate days, hours, minutes, and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the countdown with sliding animation for the last character only
var countdownText = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
var countdownElement = document.getElementById("countdown");
countdownElement.innerHTML = ''; // Clear existing content
for (var i = 0; i < countdownText.length - 1; i++) {
var charSpan = document.createElement('span');
charSpan.textContent = countdownText[i];
countdownElement.appendChild(charSpan);
}
var lastCharSpan = document.createElement('span');
lastCharSpan.className = 'countdown-char';
lastCharSpan.textContent = countdownText[countdownText.length - 1];
countdownElement.appendChild(lastCharSpan);
// Trigger animation for the last character
setTimeout(function () {
lastCharSpan.style.opacity = 1;
lastCharSpan.style.transform = "translateY(0)";
}, 100); // You can adjust the delay for the last character here
}
// Function to be executed when the countdown reaches 0
function countdownReachedZero() {
console.log("Countdown has reached zero. Your custom function can be executed here.");
// Add your custom actions here
}
function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
async function setCountdownToZero() {
var countdownElement = document.getElementById("countdown");
countdownElement.innerHTML = "0d 0h 0m 0s"; // Display "0d 0h 0m 0s" or any other desired message
await delay(3000);
window.location.href="witaj/";
}
// Update the countdown every 1 second
var x = setInterval(updateCountdown, 1000);
// Initial update
updateCountdown();