FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
html-css-javascript-projects/019-theme clock/script.js at main · hicoder88/html-css-javascript-projects · GitHub
hicoder88
/
html-css-javascript-projects
Public
forked from
solygambas/html-css-javascript-projects
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
html-css-javascript-projects
/
019-theme clock
/
script.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
89 lines (81 loc) · 2.07 KB
Breadcrumbs
html-css-javascript-projects
/
019-theme clock
/
script.js
Copy path
File metadata and controls
89 lines (81 loc) · 2.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
const
hourElement
=
document
.
querySelector
(
".hour"
)
;
const
minuteElement
=
document
.
querySelector
(
".minute"
)
;
const
secondElement
=
document
.
querySelector
(
".second"
)
;
const
timeElement
=
document
.
querySelector
(
".time"
)
;
const
dateElement
=
document
.
querySelector
(
".date"
)
;
const
toggle
=
document
.
querySelector
(
".toggle"
)
;
const
days
=
[
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
,
]
;
const
months
=
[
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
,
]
;
toggle
.
addEventListener
(
"click"
,
(
e
)
=>
{
const
html
=
document
.
querySelector
(
"html"
)
;
if
(
html
.
classList
.
contains
(
"dark"
)
)
{
html
.
classList
.
remove
(
"dark"
)
;
e
.
target
.
innerHTML
=
"Dark mode"
;
}
else
{
html
.
classList
.
add
(
"dark"
)
;
e
.
target
.
innerHTML
=
"Light mode"
;
}
}
)
;
// StackOverflow https://stackoverflow.com/questions/10756313/javascript-jquery-map-a-range-of-numbers-to-another-range-of-numbers
const
scale
=
(
num
,
in_min
,
in_max
,
out_min
,
out_max
)
=>
{
return
(
(
num
-
in_min
)
*
(
out_max
-
out_min
)
)
/
(
in_max
-
in_min
)
+
out_min
;
}
;
const
setTime
=
(
)
=>
{
const
time
=
new
Date
(
)
;
const
date
=
time
.
getDate
(
)
;
const
month
=
time
.
getMonth
(
)
;
const
day
=
time
.
getDay
(
)
;
const
hours
=
time
.
getHours
(
)
;
const
hoursForClock
=
hours
>=
13
?
hours
%
12
:
hours
;
const
minutes
=
time
.
getMinutes
(
)
;
const
seconds
=
time
.
getSeconds
(
)
;
const
ampm
=
hours
>=
12
?
"PM"
:
"AM"
;
hourElement
.
style
.
transform
=
`translate(-50%, -100%) rotate(
${
scale
(
hoursForClock
,
0
,
11
,
0
,
360
)
}
deg)`
;
minuteElement
.
style
.
transform
=
`translate(-50%, -100%) rotate(
${
scale
(
minutes
,
0
,
59
,
0
,
360
)
}
deg)`
;
secondElement
.
style
.
transform
=
`translate(-50%, -100%) rotate(
${
scale
(
seconds
,
0
,
59
,
0
,
360
)
}
deg)`
;
timeElement
.
innerHTML
=
`
${
hoursForClock
}
:
${
minutes
<
10
?
`0
${
minutes
}
`
:
minutes
}
${
ampm
}
`
;
dateElement
.
innerHTML
=
`
${
days
[
day
]
}
,
${
months
[
month
]
}
<span class="circle">
${
date
}
</span>`
;
}
;
setTime
(
)
;
setInterval
(
setTime
,
1000
)
;
Back
|
FazBrowse Home
|
New Git URL