-
Notifications
You must be signed in to change notification settings - Fork 7
/
script.js
121 lines (104 loc) · 3.85 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
let timeOfDay;
let today;
let hour;
let minute;
let second;
let day;
let month;
let year;
function updateClock() {
timeOfDay = "AM";
today = new Date();
hour = today.getHours();
minute = today.getMinutes();
second = today.getSeconds();
day = today.getDate();
month = today.getMonth();
year = today.getFullYear();
// check the time and adjust the format
minute = checkTime(minute);
second = checkTime(second);
}
function setBackgroundGradient() {
if (hour < 5) {
// early morning gradient
document.querySelector('body').style.background="linear-gradient(-45deg, #767d92, #2f4562, #152642, #081b33)";
} else if (hour < 12) {
// morning gradient
document.querySelector('body').style.background="linear-gradient(-45deg, #fa4e5e, #f9ab9e, #99b9d0, #00b2d2)";
} else if (hour < 15) {
// afternoon gradient
document.querySelector('body').style.background="linear-gradient(-45deg, #96adcf, #4570b5, #234181, #1b2966)";
} else if (hour < 22) {
// evening gradient
document.querySelector('body').style.background="linear-gradient(-45deg, #fdec6e, #e0943d, #bc361a, #391106)";
} else if (hour < 24) {
// night gradient
document.querySelector('body').style.background="linear-gradient(-45deg, #767d92, #2f4562, #152642, #081b33)";
}
// animating gradients
document.querySelector('body').style.backgroundSize="400% 400%";
document.querySelector('body').style.animation="gradient 8s ease infinite";
}
function loadGlassOverlayComponents() {
// set the greeting message according the time of the day
if (hour < 5) {
document.querySelector('#greeting').innerHTML = 'Late Night?';
} else if (hour < 12) {
document.querySelector('#greeting').innerHTML = 'Good Morning';
} else if (hour < 15) {
document.querySelector('#greeting').innerHTML = 'Good Afternoon';
} else if (hour < 22) {
document.querySelector('#greeting').innerHTML = 'Good Evening';
} else {
document.querySelector('#greeting').innerHTML = 'Late Night?';
}
// convert the time to a 12-hour clock
timeOfDay = convertTimeOfDay(hour, timeOfDay);
// set the suffix of the day
let daySuffix;
if (day === 1 || day === 21 || day === 31) daySuffix = 'st';
else if (day === 2 || day === 22) daySuffix = 'nd';
else if (day === 3 || day === 23) daySuffix = 'rd';
else daySuffix = 'th';
// get the name of the month
let monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
// display the time on the glass overlay
document.getElementById('hour').innerHTML = convertHour(hour);
document.getElementById('minute').innerHTML = ":" + minute + " ";
document.getElementById('timeSuffix').innerHTML = convertTimeOfDay(hour, timeOfDay);
// display the date on the glass overlay
document.getElementById('date').innerHTML = "Today is the " + day + daySuffix + " of " + monthNames[month] + " " + year;
// call function again after specified amount of time
let t = setTimeout(loadGlassOverlayComponents, 500);
}
function checkTime(i) {
// concatenate a zero for numbers less than 10
if (i < 10) {
i = "0" + i
}
return i;
}
function convertTimeOfDay(hour, timeOfDay) {
// make the time AM or PM
if (hour > 12) {
timeOfDay = "PM";
} else {
timeOfDay = "AM";
}
return timeOfDay;
}
function convertHour(hourValue) {
// display time in the 12-hour format
if (hourValue == 0) {
hourValue = 12;
}
if (hourValue > 12) {
hourValue = hourValue - 12;
}
return hourValue;
}
$(document).ready(setBackgroundGradient);
$(document).ready(loadGlassOverlayComponents);
updateClock();
setInterval(updateClock, 1000);