-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.js
94 lines (80 loc) · 2.77 KB
/
page.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
let currentTime = document.getElementById("current-time");
let timePosition = document.querySelector('.time');
let date = document.getElementById("current-date");
let datePosition = document.querySelector('.date');
let hideButton = document.querySelector('.hide-header-btn');
let showButton = document.querySelector('.show-header-btn');
let header = document.querySelector('.header');
let cloud = document.querySelector('.cloud')
function updateTime(){
let d = new Date();
currentTime.innerHTML = d.toLocaleTimeString();
updateGreeting();
}
function updateDate(){
let d = new Date();
date.innerHTML = d.toLocaleDateString();
}
function updateGreeting(){
const welcomeMessage = document.getElementById('welcome');
const currentHour = new Date().getHours();
if (currentHour >= 6 && currentHour < 12){
welcomeMessage.innerHTML = "Good morning!";
} else if (currentHour >= 12 && currentHour < 18){
welcomeMessage.innerHTML = "Good afternoon!";
} else {
welcomeMessage.innerHTML = "Good night!"
}
}
function checkOrientation() {
const warning = document.getElementById('landscape-warning');
if (window.innerHeight > window.innerWidth) {
// Device is in portrait mode
warning.style.display = 'flex'; // Show the warning
} else {
// Device is in landscape mode
warning.style.display = 'none'; // Hide the warning
}
}
// Check orientation on load and on resize
window.addEventListener('load', checkOrientation);
window.addEventListener('resize', checkOrientation);
updateDate();
updateTime();
setInterval(updateTime,1000);
setInterval(updateDate,1000);
if('ontouchstart' in window){
hideButton.addEventListener('touchend',function(){
header.classList.add('hidden');
hideButton.style.display = 'none';
showButton.style.display = 'block';
datePosition.style.top = 'calc(50% - 5%)';
timePosition.style.top = 'calc(50% - 5%)';
cloud.style.top = 'calc(50% - 5%)';
});
showButton.addEventListener('touchend',function(){
header.classList.remove('hidden');
hideButton.style.display = 'block';
showButton.style.display = 'none';
datePosition.style.top = '50%';
timePosition.style.top = '50%';
cloud.style.top = '50%';
});
}else{
hideButton.addEventListener('click',function(){
header.classList.add('hidden');
hideButton.style.display = 'none';
showButton.style.display = 'block';
datePosition.style.top = 'calc(50% - 10%)';
timePosition.style.top = 'calc(50% - 10%)';
cloud.style.top = 'calc(50% - 10%)';
});
showButton.addEventListener('click',function(){
header.classList.remove('hidden');
hideButton.style.display = 'block';
showButton.style.display = 'none';
datePosition.style.top = '50%';
timePosition.style.top = '50%';
cloud.style.top = '50%';
});
}