-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
71 lines (54 loc) · 2.26 KB
/
script.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
function displayDateTime() {
const currentDate = new Date();
let hours = currentDate.getHours();
let minutes = currentDate.getMinutes();
// Add leading zeros if needed
hours = (hours < 10 ? '0' : '') + hours;
minutes = (minutes < 10 ? '0' : '') + minutes;
document.getElementById('hours').innerHTML = hours;
document.getElementById('mins').innerHTML = minutes;
}
setInterval(displayDateTime, 1000);
displayDateTime();
const timebg = document.getElementById('timebg');
const date = new Date();
const hour = date.getHours();
if (hour >= 6 && hour < 8) {
timebg.style.backgroundImage = 'url("./img/bg/rff.jpg")';
} else if (hour >= 17 && hour < 18) {
timebg.style.backgroundImage = 'url("./img/bg/orange.jpg")';
} else if (hour >= 7 && hour < 17) {
timebg.style.backgroundImage = 'url("./img/bg/vert.jpg")';
} else {
timebg.style.backgroundImage = 'url("./img/bg/dark.jpg")';
}
const birthdayMonth = 0; // January (0 - 11)
const birthdayDay = 25; // 1st day of the month
function updateDaysRemaining() {
const today = new Date();
const currentYear = today.getFullYear();
let nextBirthday = new Date(currentYear, birthdayMonth, birthdayDay);
// Check if the birthday has passed this year, if yes, set it to next year
if (today > nextBirthday) {
nextBirthday = new Date(currentYear + 1, birthdayMonth, birthdayDay);
}
// Check if today is the birthday
if (
today.getMonth() === birthdayMonth &&
today.getDate() === birthdayDay
) {
// It's your birthday!
document.getElementById('daysRemaining').textContent = 'Happy Birthday Aldess!';
document.getElementById('untilbirthday').style.display = 'none'; // Hide the element
return;
}
// Calculate the difference between today and nextBirthday
const difference = nextBirthday - today;
const daysRemaining = Math.ceil(difference / (1000 * 60 * 60 * 24));
const daysRemainingElement = document.getElementById('daysRemaining');
const untilBirthdayElement = document.getElementById('untilbirthday');
// Show the correct days remaining
daysRemainingElement.textContent = `${daysRemaining} days`;
}
// Call the function to display days remaining
updateDaysRemaining();