mirror of
https://github.com/Kioubit/ColorPing
synced 2024-11-25 17:20:40 +08:00
156 lines
No EOL
4.2 KiB
HTML
156 lines
No EOL
4.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>IPV6 Canvas</title>
|
|
<style>
|
|
body {
|
|
background-color: lightslategrey;
|
|
}
|
|
|
|
#display {
|
|
margin-right: auto;
|
|
margin-left: auto;
|
|
margin-top: 2em;
|
|
display: block;
|
|
border: black 2px;
|
|
}
|
|
|
|
.information {
|
|
& {
|
|
position: absolute;
|
|
left: 0;
|
|
right: 0;
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
color: white;
|
|
background-color: rgb(100, 100, 200);
|
|
/* Collapsed */
|
|
max-width: 10em;
|
|
top: 0;
|
|
opacity: 84%;
|
|
}
|
|
|
|
& > :first-child {
|
|
display: none;
|
|
}
|
|
|
|
& > :nth-child(2) {
|
|
display: block;
|
|
}
|
|
}
|
|
|
|
.information.active {
|
|
& {
|
|
max-width: 30em;
|
|
top: 1em;
|
|
opacity: 80%;
|
|
padding-left: 0.6em;
|
|
padding-right: 0.6em;
|
|
padding-bottom: 0.6em;
|
|
}
|
|
|
|
& > :first-child {
|
|
display: block;
|
|
}
|
|
|
|
& > :nth-child(2) {
|
|
display: none;
|
|
}
|
|
}
|
|
|
|
.dot {
|
|
height: 25px;
|
|
width: 25px;
|
|
background-color: #ff8200;
|
|
border-radius: 50%;
|
|
display: inline-block;
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.text-center {
|
|
text-align: center;
|
|
}
|
|
|
|
.text-underline {
|
|
text-decoration: underline;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div>
|
|
<div class="information active" id="information">
|
|
<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>
|
|
|
|
<canvas id="display"></canvas>
|
|
</div>
|
|
</body>
|
|
<script>
|
|
const canvas = document.getElementById("display");
|
|
canvas.width = 1024;
|
|
canvas.height = 1024;
|
|
const ctx = canvas.getContext("2d")
|
|
|
|
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";
|
|
|
|
// These properties get reset on resize
|
|
ctx.imageSmoothingEnabled = false;
|
|
ctx.mozImageSmoothingEnabled = false;
|
|
ctx.webkitImageSmoothingEnabled = false;
|
|
}
|
|
|
|
window.onresize = resizeCanvas;
|
|
|
|
resizeCanvas()
|
|
|
|
ctx.fillStyle = "#000000";
|
|
ctx.font = "30px Arial";
|
|
ctx.fillText("Please wait...", 0, 200, 170);
|
|
|
|
const evtSource = new EventSource("/stream");
|
|
evtSource.addEventListener("u", (event) => {
|
|
let img = new Image();
|
|
img.src = "data:image/png;base64," + event.data;
|
|
img.onload = function () {
|
|
ctx.drawImage(img, 0, 0, 1024, 1024);
|
|
};
|
|
img.onerror = function (error) {
|
|
console.log("Img Onerror:", error);
|
|
};
|
|
});
|
|
evtSource.onerror = (err) => {
|
|
console.log(err)
|
|
document.getElementById("connectionStatus").style.setProperty("background-color", "#d20000")
|
|
};
|
|
evtSource.onopen = () => {
|
|
document.getElementById("connectionStatus").style.setProperty("background-color", "#00a30e")
|
|
};
|
|
|
|
function infoHandler() {
|
|
document.getElementById("information").classList.toggle("active");
|
|
window.scrollTo({top: 0})
|
|
}
|
|
</script>
|
|
</html> |