-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
58 lines (43 loc) · 1.57 KB
/
client.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
window.addEventListener("DOMContentLoaded", () => {
// Divider that holds the text
const divider = document.createElement("div")
divider.setAttribute("style", "justify-content: center; line-height: 1; margin: 2%; margin-top: 0.5%; border: 0.3em solid black; background-color:#ffffee")
document.body.appendChild(divider)
const messages = document.createElement("ul");
divider.appendChild(messages);
// Socket things
const websocket = new WebSocket("ws://localhost:5678/");
websocket.onmessage = ({ data }) => {
const jsonData = JSON.parse(data)
const imageBase64 = jsonData.image
const text = jsonData.message
document.getElementById('screenshot').src = imageBase64
const message = document.createElement("li");
const content = document.createTextNode(text);
message.appendChild(content);
// Icon
const icon = document.createElement("i");
icon.className = "fas fa-solid fa-copy";
icon.style.display = "none";
message.appendChild(icon);
message.addEventListener("mouseover", () => {
icon.style.display = "inline-block";
});
message.addEventListener("mouseout", () => {
icon.style.display = "none";
});
// On click copy the text, ignoring border characters
icon.addEventListener("click", async () => {
const clean_text = text.replaceAll(/[━┏┓┃┛┗─]/g, "");
await navigator.clipboard.writeText(clean_text)
// Change the icon for 1 second to indicate success
.then(() => {
icon.className = "fas fa-check";
setTimeout(() => {
icon.className = "fas fa-copy"
}, 500);
})
});
messages.prepend(message);
};
});