eaglercraft/javascript/queryTest.html

33 lines
991 B
HTML
Raw Normal View History

<html>
<head>
<title>query test</title>
<script type="text/javascript">
window.addEventListener("load", () => {
const output = document.getElementById("out");
document.getElementById("testButton").addEventListener("click", () => {
const ws = new WebSocket(document.getElementById("uriField").value);
ws.onopen = (e) => {
output.innerText = "please wait";
ws.send(document.getElementById("acceptField").value);
};
ws.onmessage = (e) => {
try {
output.innerText += JSON.stringify(JSON.parse(e.data), null, 4);
}catch(ee) {
output.innerText += e.data;
}
};
ws.onclose = (e) => {
output.innerText = output.innerText + "\n\nSocket Closed.";
};
});
});
</script>
</head>
<body style="font-family:sans-serif;">
<input type="text" id="uriField" value="ws://127.0.0.1:25565/" /><br />
<input type="text" id="acceptField" value="accept: motd" /><br />
<button id="testButton">send</button>
<pre id="out" style="font-family:sans-serif;"></pre>
</body>
</html>