Skip to content

Commit

Permalink
fix: chat observer
Browse files Browse the repository at this point in the history
  • Loading branch information
jebibot committed Sep 29, 2024
1 parent bee2ffb commit 16d0fed
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions web/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,8 @@ ${i18n.codec}: ${codecs ? `${codecs.video},${codecs.audio}` : i18n.unknown}`;
}

const chatObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((n) => {
for (const mutation of mutations) {
for (const n of mutation.addedNodes) {
if (
n.className?.startsWith(
isLive ? "live_chatting_list_item__" : "vod_chatting_item__"
Expand All @@ -1222,13 +1222,13 @@ ${i18n.codec}: ${codecs ? `${codecs.video},${codecs.audio}` : i18n.unknown}`;
const props = getReactProps(n);
const message = props?.children?.props?.chatMessage;
if (message == null) {
return;
continue;
}
const wrapper = n.querySelector(
'[class^="live_chatting_message_wrapper__"]'
);
if (wrapper == null || wrapper.dataset.timestamp) {
return;
continue;
}
if (isLive) {
const time = new Date(message.time);
Expand All @@ -1243,8 +1243,8 @@ ${i18n.codec}: ${codecs ? `${codecs.video},${codecs.audio}` : i18n.unknown}`;
}
props.children.props.messageChangeHandler?.();
}
});
});
}
}
});
chatObserver.observe(wrapper, { childList: true });
};
Expand Down Expand Up @@ -1360,11 +1360,11 @@ ${i18n.codec}: ${codecs ? `${codecs.video},${codecs.audio}` : i18n.unknown}`;

await attachChatObserver(chattingContainer, isLive);
const containerObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((n) => {
for (const mutation of mutations) {
for (const n of mutation.addedNodes) {
attachChatObserver(n, isLive);
});
});
}
}
});
containerObserver.observe(chattingContainer, { childList: true });
};
Expand All @@ -1379,11 +1379,8 @@ ${i18n.codec}: ${codecs ? `${codecs.video},${codecs.audio}` : i18n.unknown}`;
const liveObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
for (const n of mutation.addedNodes) {
if (n.querySelector != null) {
initChatFeatures(
n.tagName === "ASIDE" ? n : n.querySelector("aside"),
true
);
if (n.tagName === "ASIDE") {
initChatFeatures(n, true);
}
}
}
Expand Down

0 comments on commit 16d0fed

Please sign in to comment.