Skip to content

Commit 9bdddb2

Browse files
authored
Time Viewer page
It is a dynamic handling page which shows us time, helps us in noting our focus for the day and changes its backgronud according to the timing.
1 parent 6b3fdd3 commit 9bdddb2

6 files changed

Lines changed: 166 additions & 0 deletions

File tree

‎jsLib/afternoon.jpg‎

32.1 KB
Loading

‎jsLib/index.html‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="style.css">
7+
<title>Hello there!</title>
8+
</head>
9+
<body>
10+
<time id="time">12:18:06 PM</time>
11+
<h1>
12+
<span id="greeting">Good Afternoon</span>
13+
<span id="name" contenteditable="true">[Enter your name]</span>
14+
</h1>
15+
16+
<h2>What Is Your Focus For Today?</h2>
17+
<h2 id="focus" contenteditable="true">[Enter Focus]</h2>
18+
<script src="main.js"></script>
19+
</body>
20+
</html>

‎jsLib/main.js‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// DOM Elements
2+
const time = document.getElementById('time'),
3+
greeting = document.getElementById('greeting'),
4+
name = document.getElementById('name'),
5+
focus = document.getElementById('focus');
6+
7+
// Options
8+
const showAmPm = true;
9+
10+
// Show Time
11+
function showTime() {
12+
let today = new Date(),
13+
hour = today.getHours(),
14+
min = today.getMinutes(),
15+
sec = today.getSeconds();
16+
17+
// Set AM or PM
18+
const amPm = hour >= 12 ? 'PM' : 'AM';
19+
20+
// 12hr Format
21+
hour = hour % 12 || 12;
22+
23+
// Output Time
24+
time.innerHTML = `${hour}<span>:</span>${addZero(min)}<span>:</span>${addZero(
25+
sec
26+
)} ${showAmPm ? amPm : ''}`;
27+
28+
setTimeout(showTime, 1000);
29+
}
30+
31+
// Add Zeros
32+
function addZero(n) {
33+
return (parseInt(n, 10) < 10 ? '0' : '') + n;
34+
}
35+
36+
// Set Background and Greeting
37+
function setBgGreet() {
38+
let today = new Date(),
39+
hour = today.getHours();
40+
41+
if (hour < 12) {
42+
// Morning
43+
document.body.style.backgroundImage = "url('https://i.ibb.co/rbmx2RK/morning.jpg')";
44+
greeting.textContent = 'Good Morning, ';
45+
} else if (hour < 18) {
46+
// Afternoon
47+
document.body.style.backgroundImage = "url('https://i.ibb.co/wKtVjYM/night.jpg')";
48+
greeting.textContent = 'Good Afternoon, ';
49+
} else {
50+
// Evening
51+
document.body.style.backgroundImage = "url('https://i.ibb.co/JQRJ91J/afternoon.jpg')";
52+
greeting.textContent = 'Good Evening, ';
53+
document.body.style.color = 'white';
54+
}
55+
}
56+
57+
// Get Name
58+
function getName() {
59+
if (localStorage.getItem('name') === null) {
60+
name.textContent = '[Enter Name]';
61+
} else {
62+
name.textContent = localStorage.getItem('name');
63+
}
64+
}
65+
66+
// Set Name
67+
function setName(e) {
68+
if (e.type === 'keypress') {
69+
// Make sure enter is pressed
70+
if (e.which == 13 || e.keyCode == 13) {
71+
localStorage.setItem('name', e.target.innerText);
72+
name.blur();
73+
}
74+
} else {
75+
localStorage.setItem('name', e.target.innerText);
76+
}
77+
}
78+
79+
// Get Focus
80+
function getFocus() {
81+
if (localStorage.getItem('focus') === null) {
82+
focus.textContent = '[Enter Focus]';
83+
} else {
84+
focus.textContent = localStorage.getItem('focus');
85+
}
86+
}
87+
88+
// Set Focus
89+
function setFocus(e) {
90+
if (e.type === 'keypress') {
91+
// Make sure enter is pressed
92+
if (e.which == 13 || e.keyCode == 13) {
93+
localStorage.setItem('focus', e.target.innerText);
94+
focus.blur();
95+
}
96+
} else {
97+
localStorage.setItem('focus', e.target.innerText);
98+
}
99+
}
100+
101+
name.addEventListener('keypress', setName);
102+
name.addEventListener('blur', setName);
103+
focus.addEventListener('keypress', setFocus);
104+
focus.addEventListener('blur', setFocus);
105+
106+
// Run
107+
showTime();
108+
setBgGreet();
109+
getName();
110+
getFocus();

‎jsLib/morning.jpg‎

65.4 KB
Loading

‎jsLib/night.jpg‎

19.4 KB
Loading

‎jsLib/style.css‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
* {
2+
box-sizing: border-box;
3+
margin: 0;
4+
padding: 0;
5+
}
6+
7+
body {
8+
font-family: 'Quicksand', sans-serif;
9+
display: flex;
10+
flex-direction: column;
11+
align-items: center;
12+
justify-content: center;
13+
text-align: center;
14+
height: 100vh;
15+
color: black;
16+
}
17+
18+
#time {
19+
font-size: 8rem;
20+
}
21+
22+
h1 {
23+
margin-bottom: 3rem;
24+
}
25+
26+
h2 {
27+
margin-bottom: 0.5rem;
28+
opacity: 0.6;
29+
}
30+
31+
@media (max-width: 700px) {
32+
#time {
33+
font-size: 6rem;
34+
}
35+
}
36+

0 commit comments

Comments
 (0)