You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB
HTML

2 years ago
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Draw draw draw</title>
<script src="wss.js"></script>
2 years ago
<script src="draw.js" defer></script>
<link rel="stylesheet" href="style.css" />
2 years ago
</head>
<body>
<h1>Disegna <span id="theme"></span></h1>
<div id="svg-container">
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
id="svgElement"
x="0px"
y="0px"
width="500px"
height="500px"
viewBox="0 0 500 500"
enable-background="new 0 0 500 500"
xml:space="preserve"
></svg>
2 years ago
<button id="submit">Send</button>
2 years ago
</div>
<script>
const theme = document.querySelector("#theme");
const socket = new ReconnectingWebSocket(location.origin.replace(/^http/, "ws"));
2 years ago
socket.onmessage = (event) => {
let message;
try {
message = JSON.parse(event.data);
} catch (e) {}
if (message?.type == "theme") {
theme.innerHTML = message.theme;
}
};
document.querySelector("#submit").addEventListener("click", (event) => {
const paths = Array.from(document.querySelectorAll("#svgElement path")).reduce(
(accumulator, current) => {
return (accumulator += current.getAttribute("d"));
},
""
);
2 years ago
if (paths == "") return;
2 years ago
socket.send(JSON.stringify({ type: "drawings", paths: paths }));
for (const path of document.querySelectorAll("#svgElement path")) {
path.remove();
}
2 years ago
});
</script>
</body>
</html>