summaryrefslogtreecommitdiff
path: root/chat.js
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-12-12 00:43:17 +0500
committerilotterytea <iltsu@alright.party>2025-12-12 00:43:17 +0500
commit95893a324a761de671260b526143bd878feaaa53 (patch)
tree4ab8bece822b67199fdd56a295b0845c9f80941b /chat.js
parent3ef6044be93e16ebc5325921ebfcc5c89878e999 (diff)
feat: show emotes!!!
Diffstat (limited to 'chat.js')
-rw-r--r--chat.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/chat.js b/chat.js
index 080fb4c..f3e81ef 100644
--- a/chat.js
+++ b/chat.js
@@ -2,4 +2,34 @@ function getChannelName() {
const path = window.location.pathname.split('/').filter(Boolean);
if (path.length == 1) return path[path.length - 1];
return null;
+}
+
+function replaceEmotes(node, emotes) {
+ const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, null);
+
+ const textNodes = [];
+ while (walker.nextNode()) textNodes.push(walker.currentNode);
+
+ textNodes.forEach(x => {
+ const parent = x.parentNode;
+ const frag = document.createDocumentFragment();
+ const words = x.textContent.split(/(\s+)/);
+
+ words.forEach(word => {
+ if (emotes[word]) {
+ const emote = emotes[word];
+
+ const img = document.createElement("img");
+ img.src = emote.miniatureurl;
+ img.alt = word;
+ img.classList.add("tiny-emote");
+ img.addEventListener("mouseenter", () => console.log(word));
+ frag.appendChild(img);
+ } else {
+ frag.appendChild(document.createTextNode(word));
+ }
+ });
+
+ parent.replaceChild(frag, x);
+ });
} \ No newline at end of file