Files
Overlays/weather_overlay/test_websocket.html

35 lines
1.3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>WebSocket Test</title>
</head>
<body>
<h1>WebSocket Test</h1>
<p style="font-size: 0.8em; color: #666;">
Last Modified: <script>document.write(document.lastModified);</script>
</p>
<input type="text" id="message" placeholder="Enter message">
<button onclick="sendMessage()">Send</button>
<ul id="messages"></ul>
<script>
const ws = new WebSocket("wss://overlays.ramforth.net/weather_ws");
ws.onmessage = function(event) {
const messages = document.getElementById('messages');
const message = document.createElement('li');
const timestamp = new Date().toLocaleTimeString();
const content = document.createTextNode(`[${timestamp}] ${event.data}`);
message.appendChild(content);
messages.appendChild(message);
};
function sendMessage() {
const input = document.getElementById("message");
const location = input.value;
if (location) {
ws.send(JSON.stringify({ "location": location }));
input.value = '';
}
}
</script>
</body>
</html>