-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverlay.html
48 lines (42 loc) · 1.45 KB
/
overlay.html
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
<!DOCTYPE html>
<html>
<head>
<title>Chat Layer</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<p id="message">!message {sua mensagem}</p>
<script>
window.onload = loadOverlayProperties();
function loadOverlayProperties() {
document.getElementById("message").innerHTML =
localStorage.getItem("message");
document.body.style.background = localStorage.getItem("background");
}
var ws = new WebSocket("ws://localhost:5678/");
ws.onmessage = function (event) {
const data = JSON.parse(event.data);
if (localStorage.getItem("message") !== data.message) {
localStorage.setItem("message", data.message);
document.getElementById("message").innerHTML =
localStorage.getItem("message");
}
if (localStorage.getItem("background") !== data.background) {
localStorage.setItem("background", data.background);
document.body.style.background = localStorage.getItem("background");
}
};
ws.onclose = function (event) {
if (event.wasClean) {
alert(
`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`
);
} else {
// e.g. server process killed or network down
// event.code is usually 1006 in this case
alert("[close] Connection died");
}
};
</script>
</body>
</html>