diff --git a/assets/js/comments.js b/assets/js/comments.js
index d454fe382..655e78aca 100644
--- a/assets/js/comments.js
+++ b/assets/js/comments.js
@@ -3,6 +3,24 @@ var video_data = JSON.parse(document.getElementById('video_data').textContent);
var spinnerHTML = '
';
var spinnerHTMLwithHR = spinnerHTML + '
';
+// Moved channel emoji helper to top for safe access
+helpers.replaceChannelEmojis = function(html) {
+ if (!video_data.channelEmojis) return html;
+ // Use DOM parser to replace only in text nodes
+ const parser = new DOMParser();
+ const doc = parser.parseFromString(html, 'text/html');
+ const textNodes = doc.createTreeWalker(doc.body, NodeFilter.SHOW_TEXT);
+
+ let node;
+ while ((node = textNodes.nextNode())) {
+ node.textContent = node.textContent.replace(/:([a-zA-Z0-9_]+):/g, (match, name) => {
+ const emoji = video_data.channelEmojis[name];
+ return emoji ? `
` : match;
+ });
+ }
+ return doc.body.innerHTML;
+};
+
String.prototype.supplant = function (o) {
return this.replace(/{([^{}]*)}/g, function (a, b) {
var r = o[b];
@@ -10,15 +28,6 @@ String.prototype.supplant = function (o) {
});
};
-// Added channel emoji conversion helper
-helpers.replaceChannelEmojis = function(html) {
- if (!video_data.channelEmojis) return html;
- return html.replace(/:([a-zA-Z0-9_]+):/g, (match, name) => {
- const emoji = video_data.channelEmojis[name];
- return emoji ? `
` : match;
- });
-};
-
function toggle_comments(event) {
// ... existing code ...
}
@@ -30,31 +39,19 @@ function get_youtube_comments() {
helpers.xhr('GET', url, {retries: 5, entity_name: 'comments'}, {
on200: function (response) {
- var commentInnerHtml = ' \
- \
-
\
- [ − ] \
- {commentsText} \
-
\
-
\
- '
- if (video_data.support_reddit) {
- commentInnerHtml += ' \
- {redditComments} \
- \
- '
- }
- commentInnerHtml += ' \
-
\
- {contentHtml}
\
-
'
+ var commentInnerHtml = `
+
+
+
+ ${video_data.support_reddit ? ` ` : ''}
+
+
${helpers.replaceChannelEmojis(response.contentHtml)}
+
+
`;
- // Apply channel emoji conversion
- var processedContentHtml = helpers.replaceChannelEmojis(response.contentHtml);
- commentInnerHtml = commentInnerHtml.supplant({
- contentHtml: processedContentHtml,
- commentsText: video_data.comments_text,
- redditComments: video_data.reddit_comments_text
+ // Rebind handlers after DOM update
+ document.querySelectorAll('.comment-toggle').forEach(el => {
+ el.addEventListener('click', toggle_comments);
});
comments.innerHTML = commentInnerHtml;
},
diff --git a/assets/js/community.js b/assets/js/community.js
index 7c99b81bf..b0918e9e5 100644
--- a/assets/js/community.js
+++ b/assets/js/community.js
@@ -9,8 +9,9 @@ function hide_youtube_replies(event) {
var body = target.parentNode.parentNode.children[1];
body.style.display = 'none';
- target.innerHTML = sub_text;
+ target.innerHTML = sub_text; // Show "show replies" label
target.onclick = show_youtube_replies;
+ // Swap data attributes for next toggle
target.setAttribute('data-inner-text', inner_text);
target.setAttribute('data-sub-text', sub_text);
}
@@ -23,12 +24,17 @@ function show_youtube_replies(event) {
var body = target.parentNode.parentNode.children[1];
body.style.display = '';
- target.innerHTML = inner_text; // Show "hide replies" label
+ target.innerHTML = inner_text; // Show "hide replies" label
target.onclick = hide_youtube_replies;
+ // Swap data attributes for next toggle
target.setAttribute('data-inner-text', sub_text);
target.setAttribute('data-sub-text', inner_text);
}
-function get_youtube_replies(target, load_more) {
- // ... existing code ...
+// Ensure community.js is included in watch pages
+if (typeof get_youtube_replies === 'undefined' && window.location.pathname.includes('/watch')) {
+ // Implement watch-page specific reply loader or include community.js
+ console.error('Community functions not initialized for watch page');
}
+
+// ... rest of existing code ...