html: Support mobile & simplify

This commit is contained in:
Kioubit 2024-06-18 15:49:17 +03:00
parent 8f2ff955e9
commit cc9be27ab6

View file

@ -2,46 +2,64 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>IPV6Canvas</title> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>IPV6 Canvas</title>
<style> <style>
body{ body {
background-color: lightslategrey; background-color: lightslategrey;
} }
#display{
#display {
margin-right: auto; margin-right: auto;
margin-left: auto; margin-left: auto;
margin-top: 1em; margin-top: 2em;
display: block; display: block;
border: black 2px; border: black 2px;
} }
#collapsed-information{
display: none; .information {
position: absolute; & {
left: 0; position: absolute;
right: 0; left: 0;
margin-left: auto; right: 0;
margin-right: auto; margin-left: auto;
width: 10em; margin-right: auto;
top: 0; color: white;
opacity: 84%; background-color: rgb(100, 100, 200);
color: white; /* Collapsed */
background-color: rgb(100, 100, 200); max-width: 10em;
top: 0;
opacity: 84%;
}
& > :first-child {
display: none;
}
& > :nth-child(2) {
display: block;
}
} }
#information{
position: absolute; .information.active {
left: 0; & {
right: 0; max-width: 30em;
margin-left: auto; top: 1em;
margin-right: auto; opacity: 80%;
width: 30em; padding-left: 0.6em;
top: 1em; padding-right: 0.6em;
opacity: 80%; padding-bottom: 0.6em;
padding-left: 0.6em; }
padding-right: 0.6em;
padding-bottom: 0.6em; & > :first-child {
color: white; display: block;
background-color: rgb(100, 100, 200); }
& > :nth-child(2) {
display: none;
}
} }
.dot { .dot {
height: 25px; height: 25px;
width: 25px; width: 25px;
@ -50,42 +68,67 @@
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
} }
.center {
align-items: center; .text-center {
display: flex; text-align: center;
justify-content: center; }
.text-underline {
text-decoration: underline;
} }
</style> </style>
</head> </head>
<body> <body>
<div> <div>
<div id="collapsed-information"> <div class="information active" id="information">
<div class="center"><a style="text-decoration: underline" onclick="infoHandler(true)">Show information</a></div> <div>
<h2>IPv6 Canvas</h2>
<div style="overflow-x: auto">
<b>ping {{.BaseIP}}XXXX:YYYY:11RR:GGBB</b>
<br>Substitute coordinates and color, then ping. Values are hexadecimal.
</div>
<br>Canvas size: {{.CanvasWidth}}x{{.CanvasHeight}}<br>
Connection status: <span id="connectionStatus" class="dot"></span>
<span style="float: right">
<a class="text-underline" onclick="infoHandler()">Collapse</a>
</span>
</div>
<div class="text-center">
<a class="text-underline" onclick="infoHandler()">Show information</a>
</div>
</div> </div>
<div id="information">
<h2>IPv6 Canvas</h2> <canvas id="display"></canvas>
<b>ping {{.BaseIP}}XXXX:YYYY:11RR:GGBB</b>
<br>Substitute coordinates and color, then ping. Values are hexadecimal.<br>
<br>Canvas size: {{.CanvasWidth}}x{{.CanvasHeight}}<br>
Connection status: <span id="connectionStatus" class="dot"></span>
<span style="float: right"><a style="text-decoration: underline" onclick="infoHandler(false)">Collapse</a></span>
<br>
</div>
<canvas id="display" width="1024" height="1024"></canvas>
</div> </div>
</body> </body>
<script> <script>
const canvas = document.getElementById("display"); const canvas = document.getElementById("display");
const ctx = canvas.getContext("2d") const ctx = canvas.getContext("2d")
const evtSource = new EventSource("/stream");
ctx.imageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false;
ctx.mozImageSmoothingEnabled = false; ctx.mozImageSmoothingEnabled = false;
ctx.webkitImageSmoothingEnabled = false; ctx.webkitImageSmoothingEnabled = false;
//ctx.scale(1.9, 1.9) canvas.width = 1024;
canvas.height = 1024;
async function resizeCanvas() {
let desiredSize = document.documentElement.clientWidth - 20;
if (desiredSize > 1024) {
desiredSize = 1024
}
canvas.style.width = desiredSize.toString() + "px";
canvas.style.height = desiredSize.toString() + "px";
}
window.onresize = resizeCanvas;
resizeCanvas()
ctx.fillStyle = "#000000"; ctx.fillStyle = "#000000";
ctx.font = "30px Arial"; ctx.font = "30px Arial";
ctx.fillText("Please wait...", 0, 200,170); ctx.fillText("Please wait...", 0, 200, 170);
const evtSource = new EventSource("/stream");
evtSource.addEventListener("u", (event) => { evtSource.addEventListener("u", (event) => {
let img = new Image(); let img = new Image();
img.src = "data:image/png;base64," + event.data; img.src = "data:image/png;base64," + event.data;
@ -98,19 +141,15 @@
}); });
evtSource.onerror = (err) => { evtSource.onerror = (err) => {
console.log(err) console.log(err)
document.getElementById("connectionStatus").style.setProperty("background-color","#d20000") document.getElementById("connectionStatus").style.setProperty("background-color", "#d20000")
}; };
evtSource.onopen = () => { evtSource.onopen = () => {
document.getElementById("connectionStatus").style.setProperty("background-color","#00a30e") document.getElementById("connectionStatus").style.setProperty("background-color", "#00a30e")
}; };
function infoHandler(expand) {
if (expand) { function infoHandler() {
document.getElementById("collapsed-information").style.display = "none"; document.getElementById("information").classList.toggle("active");
document.getElementById("information").style.display = "block"; window.scrollTo({top: 0})
} else {
document.getElementById("collapsed-information").style.display = "block";
document.getElementById("information").style.display = "none";
}
} }
</script> </script>
</html> </html>