Files
obs-keyboard-overlay/public/overlay.js
T
2026-06-19 15:51:23 +02:00

28 lines
808 B
JavaScript

const ws = new WebSocket("ws://" + location.hostname + ":3000");
ws.addEventListener("message", (event) => {
const { type, key } = JSON.parse(event.data);
if (!key) return;
const el = document.getElementById(key);
if (!el) return;
if (type === "keydown") {
el.classList.add("active");
} else if (type === "keyup") {
el.classList.remove("active");
}
});
ws.addEventListener("open", () => {
fetch("/keymap.json")
.then(r => r.json())
.then(keymap => {
const mapped = new Set(Object.values(keymap).map(k => k.toUpperCase()));
document.querySelectorAll(".key").forEach(el => {
if (!mapped.has(el.id)) {
el.style.visibility = "hidden";
}
});
});
});