From 4e23f34e6e45c7da718e923b94d831a4b5badcb7 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 26 Oct 2025 16:54:00 +0500 Subject: feat: twitch emotes --- scripts/chat.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/scripts/chat.js b/scripts/chat.js index a5ecafc..da54647 100644 --- a/scripts/chat.js +++ b/scripts/chat.js @@ -63,6 +63,24 @@ function addMessage(message) { } } + // parsing twitch emotes + if ("emotes" in message.tags && message.tags["emotes"].length > 0) { + const parts = message.tags["emotes"].split("/"); + for (const part of parts) { + const p = part.split(":"); + const id = p[0]; + const positions = p[1].split(","); + + for (const pos of positions) { + const p = pos.split("-"); + const start = p[0]; + const end = p[1]; + const emotename = message.params[1].substring(parseInt(start), parseInt(end) + 1); + emotes[emotename] = `https://static-cdn.jtvnw.net/emoticons/v2/${id}/default/dark/1.0`; + } + } + } + // username const usernameElem = document.createElement("span"); elem.append(usernameElem); @@ -123,7 +141,9 @@ function connectToChat(host, nick, password, room) { if (l.length == 0) { continue; } - addMessage(parseIRCMessage(l)); + let m = parseIRCMessage(l); + console.log(m); + addMessage(m); } }); -- cgit v1.2.3