-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
145 lines (135 loc) · 4.23 KB
/
index.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- tailwind css -->
<script src="https://cdn.tailwindcss.com"></script>
<title>My Clock</title>
</head>
<!-- custom style -->
<style>
.container {
box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
}
.container.dark {
box-shadow: rgba(255, 255, 255, 0.35) 0px 5px 15px;
}
html.dark {
--tw-bg-opacity: 1;
background-color: rgba(31, 41, 55, var(--tw-bg-opacity));
color: white;
}
html.dark .dark\:ml-6 {
margin-left: 1.5rem;
}
</style>
<body>
<h1 class="font-bold text-center my-[2rem] text-[4rem]">MY CLOCK</h1>
<p
class="text-center text-[2rem] underline underline-offset-8"
id="greeting"
></p>
<div class="flex justify-center w-full">
<div
class="container w-[50%] mx-[3rem] my-[2rem] py-4 text-center rounded-lg sm:w-100 sm:mx-0"
>
<p class="lg:text-[4rem] sm:text-[100%] py-2" id="clock"></p>
<p class="lg:text-[2.5rem] sm:text-[100%] py-2" id="date"></p>
</div>
</div>
<div class="flex justify-center">
<p class="mx-2">Switch Mode</p>
<button
onclick="setTheme()"
class="w-12 h-6 rounded-full p-1 bg-gray-400 dark:bg-gray-600 transition-colors duration-500 ease-in focus:outline-none focus:ring-2 focus:ring-blue-700 dark:focus:ring-blue-600 focus:border-transparent"
>
<div
id="toggle"
class="rounded-full w-4 h-4 bg-green-600 dark:bg-blue-500 ml-0 dark:ml-6 pointer-events-none transition-all duration-300 ease-out"
></div>
</button>
</div>
<!-- custom js -->
<script>
window.onload = function () {
// class of user
class User {
constructor(name) {
this.name = name
}
}
// function clock
function clock() {
let date = new Date()
let hour = date.getHours()
let minute = date.getMinutes()
let second = date.getSeconds()
let status = 'AM'
let greeting = ''
if (hour == 0) {
hour = 12
}
if (hour > 12) {
hour = hour - 12
status = 'PM'
}
// check if AM or PM
if (status == 'PM') {
greeting = 'Good Evening'
} else {
greeting = 'Good Morning'
}
hour = hour < 10 ? '0' + hour : hour
minute = minute < 10 ? '0' + minute : minute
second = second < 10 ? '0' + second : second
let time = hour + ':' + minute + ':' + second + ' ' + status
let appendClock = document.querySelector('#clock')
appendClock.innerHTML = time
appendClock.textContent = time
// create user
const userNow = new User('Yehezkiel')
// set greeting to user
let greetingUser = greeting + ' ' + userNow.name
let appendGreeting = document.querySelector('#greeting')
appendGreeting.innerHTML = greetingUser
appendGreeting.textContent = greetingUser
setTimeout(clock, 1000)
}
// function date
function showDate() {
let date = new Date()
let year = date.getFullYear()
let day = date.getDate()
const months = [
'Januari',
'Feburari',
'Maret',
'April',
'Mei',
'Juni',
'Juli',
'Agustus',
'September',
'Oktober',
'November',
'Desember',
]
let month = months[date.getMonth()]
let dates = day + ' - ' + month + ' - ' + year
let appendDate = document.querySelector('#date')
appendDate.innerHTML = dates
appendDate.textContent = dates
}
clock()
showDate()
}
// set Theme
function setTheme(event) {
document.documentElement.classList.toggle('dark')
document.querySelector('.container').classList.toggle('dark')
}
</script>
</body>
</html>