buggy init :3
This commit is contained in:
commit
0f96641be1
2179 changed files with 388452 additions and 0 deletions
43
startpage/js/modules/Clock.js
Executable file
43
startpage/js/modules/Clock.js
Executable file
|
@ -0,0 +1,43 @@
|
|||
export class Clock {
|
||||
constructor(clockElement, greetingElement) {
|
||||
this.clockElement = clockElement;
|
||||
this.greetingElement = greetingElement;
|
||||
this.interval = null;
|
||||
}
|
||||
|
||||
start() {
|
||||
this.update();
|
||||
this.interval = setInterval(() => this.update(), 1000);
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (this.interval) clearInterval(this.interval);
|
||||
}
|
||||
|
||||
update() {
|
||||
const now = new Date();
|
||||
this.clockElement.textContent = now.toLocaleTimeString('en-US', {
|
||||
hour12: false,
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
this.updateGreeting();
|
||||
}
|
||||
|
||||
updateGreeting() {
|
||||
this.greetingElement.textContent = this.getGreeting();
|
||||
}
|
||||
|
||||
getGreeting() {
|
||||
const hour = new Date().getHours();
|
||||
let greeting = '';
|
||||
|
||||
if (hour >= 5 && hour < 12) greeting = 'Good morning';
|
||||
else if (hour >= 12 && hour < 18) greeting = 'Good afternoon';
|
||||
else if (hour >= 18 && hour < 22) greeting = 'Good evening';
|
||||
else greeting = 'Good night';
|
||||
|
||||
const name = localStorage.getItem('username');
|
||||
return name ? `${greeting}, ${name}` : greeting;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue