1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-25 12:57:53 +00:00
MarlinFirmware/data/www/marlin.js

25 lines
684 B
JavaScript
Raw Normal View History

2019-03-13 05:48:08 +00:00
document.addEventListener('DOMContentLoaded', () => {
const ws = new WebSocket(`ws://${location.host}/ws`);
ws.onmessage = (e) => {
if (typeof e.data === 'string') {
let node = document.createElement('li');
let text = document.createTextNode(e.data);
node.appendChild(text);
document.getElementById('serial-output').appendChild(node);
}
};
document.getElementById('serial-command-form').addEventListener('submit', (e) => {
e.preventDefault();
let value = document.getElementById('serial-command').value.trim();
if (!value) return;
ws.send(`${value}\n`);
document.getElementById('serial-command').value = '';
});
});