-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathonline_offline.php
108 lines (95 loc) · 3.27 KB
/
online_offline.php
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
<?php
require("db.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>NodeMCU Status</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link href="https://fonts.googleapis.com/css?family=Rubik:400,500" rel="stylesheet"> -->
<style>
div.container1 {
height: 10vh;
width: 93.5%;
display: flex;
justify-content: center;
align-items: center;
}
div.online-indicator {
display: inline-block;
width: 25px;
height: 25px;
margin-right: 10px;
border-radius: 50%;
position: relative;
}
span.blink {
display: block;
width: 25px;
height: 25px;
opacity: 0.7;
border-radius: 50%;
animation: blink 1s linear infinite;
}
p.online-text {
color: #0fcc45;
display: inline;
font-family: "Rubik", sans-serif;
font-weight: 400;
text-shadow: 0px 3px 6px rgba(150, 150, 150, 0.2);
position: relative;
cursor: pointer;
}
/* Change the color of the online status when disconnected */
p.online-text.disconnected {
color: #ff4f4f;
}
/* Change the color of the blink and online indicator when disconnected */
p.online-text.disconnected+div.online-indicator span.blink {
background-color: #ff4f4f;
}
p.online-text.disconnected+div.online-indicator {
background-color: #ff4f4f;
}
/*Animations*/
@keyframes blink {
100% {
transform: scale(2, 2);
opacity: 0;
}
}
</style>
</head>
<body>
<div class="container1">
<div class="online-indicator">
<span class="blink"></span>
</div>
<p class="online-text" id="status">NodeMCU is connected!</p>
</div>
<script>
// Get the status element
const statusElement = document.getElementById('status');
// Listen for changes in the online status
window.addEventListener('online', updateStatus);
window.addEventListener('offline', updateStatus);
// Function to update the status based on the online status
function updateStatus() {
if (navigator.onLine) {
statusElement.classList.remove('disconnected');
statusElement.innerText = 'NodeMCU is connected!';
document.querySelector('.blink').style.backgroundColor = '#0fcc45';
document.querySelector('.online-indicator').style.backgroundColor = '#0fcc45';
} else {
statusElement.classList.add('disconnected');
statusElement.innerText = 'NodeMCU is disconnected!';
document.querySelector('.blink').style.backgroundColor = '#ff4f4f';
document.querySelector('.online-indicator').style.backgroundColor = '#ff4f4f';
}
}
// Initial status update
updateStatus();
</script>
</body>
</html