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.
72 lines
1.8 KiB
HTML
72 lines
1.8 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>
|
||
2 years ago
|
<script src="wss.js"></script>
|
||
2 years ago
|
<script src="draw.js" defer></script>
|
||
2 years ago
|
<link rel="stylesheet" href="style.css" />
|
||
2 years ago
|
</head>
|
||
|
<body>
|
||
2 years ago
|
<h1>Draw <span id="theme"></span></h1>
|
||
2 years ago
|
<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>
|
||
|
<button id="erase">Cancel</button>
|
||
2 years ago
|
</div>
|
||
|
|
||
|
<script>
|
||
|
const theme = document.querySelector("#theme");
|
||
2 years ago
|
const erase = document.querySelector("#erase");
|
||
|
const deletePath = () => {
|
||
|
for (const path of document.querySelectorAll("#svgElement path")) {
|
||
|
path.remove();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
erase.addEventListener("click", () => deletePath());
|
||
2 years ago
|
|
||
2 years ago
|
const socket = new ReconnectingWebSocket(
|
||
|
location.origin.replace(/^http/, "ws") + "{{location}}"
|
||
|
);
|
||
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 }));
|
||
2 years ago
|
deletePath();
|
||
2 years ago
|
});
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|