From efb6d3fe70d3dbe3f7d36dfea614558fb002552f Mon Sep 17 00:00:00 2001 From: epicsam123 <92618898+epicsam123@users.noreply.github.com> Date: Thu, 17 Apr 2025 12:54:35 -0400 Subject: [PATCH] Added loaded text for replies, added title for hover, show only final total count --- assets/js/comments.js | 33 ++++++++++++++++++------------- locales/en-US.json | 1 + src/invidious/views/community.ecr | 1 + src/invidious/views/post.ecr | 1 + src/invidious/views/watch.ecr | 4 +++- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/assets/js/comments.js b/assets/js/comments.js index abe423ce..72d17d9b 100644 --- a/assets/js/comments.js +++ b/assets/js/comments.js @@ -123,17 +123,17 @@ function get_youtube_comments() { } function format_count_load_more(content, current_count, total_count) { - var load_more_end_str = content.split('data-load-more'); - if (load_more_end_str.length === 1) - return [content, false]; // no Load More button, return false for has_more_replies - load_more_end_str = load_more_end_str[1].split('\n')[0]; // ' >("Load more" translated string)' - var slice_index = content.indexOf(load_more_end_str) + load_more_end_str.length - 4; // backtrace - var num_remaining = total_count - current_count; - return [ - // More replies may have been added since initally loading parent comment - content.slice(0, slice_index) + ' (+' + (num_remaining > 0 ? num_remaining : '?') + ')' + content.slice(slice_index), - true // Load More button present, return true for has_more_replies - ]; + var load_more_end_str = content.split('data-load-more'); + if (load_more_end_str.length === 1) + return [content, false]; // no Load More button, return false for has_more_replies + load_more_end_str = load_more_end_str[1].split('\n')[0]; // ' >("Load more" translated string)' + var slice_index = content.indexOf(load_more_end_str) + load_more_end_str.length - 4; // backtrace + var num_remaining = total_count - current_count; + return [ + // More replies may have been added since initally loading parent comment + content.slice(0, slice_index) + ' (+' + (num_remaining > 0 ? num_remaining : '?') + ')' + content.slice(slice_index), + true // Load More button present, return true for has_more_replies + ]; } function format_count_toggle_replies_button(toggle_reply_button, current_count, total_count, has_more_replies) { @@ -141,6 +141,7 @@ function format_count_toggle_replies_button(toggle_reply_button, current_count, // Accept the final current count as the total (comments may have been added or removed since loading) total_count = current_count; } else if (current_count >= total_count) { + // An unknown number of new replies have been added since retrieving data total_count = '?'; } @@ -148,10 +149,13 @@ function format_count_toggle_replies_button(toggle_reply_button, current_count, ['data-sub-text', 'data-inner-text'].forEach(attr => { toggle_reply_button.setAttribute(attr, toggle_reply_button.getAttribute(attr) - .replace(/\(\d+\/\d+\)/, ' (' + current_count + '/' + total_count + ')') + .replace(/\d+\/\d+/, total_count === current_count + ? total_count + : current_count + '/' + total_count + ) ); }); - toggle_reply_button.textContent = toggle_reply_button.getAttribute('data-sub-text'); + toggle_reply_button.textContent = toggle_reply_button.title = toggle_reply_button.getAttribute('data-sub-text'); } function get_youtube_replies(target, load_more, load_replies) { @@ -206,7 +210,8 @@ function get_youtube_replies(target, load_more, load_replies) { a.onclick = hide_youtube_replies; var num_total_replies = originalHTML.split('data-load-replies')[1].match(/\d+/)[0] - 0; - var num_replies_text = ' (0/0)'; // replace later + // Replaced later with real counts + var num_replies_text = ' (0/0 ' + video_data.replies_loaded_text + ')'; var hide_replies_text = video_data.hide_replies_text + num_replies_text; a.setAttribute('data-sub-text', hide_replies_text); a.setAttribute('data-inner-text', video_data.show_replies_text + num_replies_text); diff --git a/locales/en-US.json b/locales/en-US.json index c23f6bc3..fdeffb56 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -219,6 +219,7 @@ "View Reddit comments": "View Reddit comments", "Hide replies": "Hide replies", "Show replies": "Show replies", + "Replies loaded": "loaded", "Incorrect password": "Incorrect password", "Wrong answer": "Wrong answer", "Erroneous CAPTCHA": "Erroneous CAPTCHA", diff --git a/src/invidious/views/community.ecr b/src/invidious/views/community.ecr index d2a305d3..0976cea9 100644 --- a/src/invidious/views/community.ecr +++ b/src/invidious/views/community.ecr @@ -39,6 +39,7 @@ "comments_text" => HTML.escape(translate(locale, "View `x` comments", "{commentCount}")), "hide_replies_text" => HTML.escape(translate(locale, "Hide replies")), "show_replies_text" => HTML.escape(translate(locale, "Show replies")), + "replies_loaded_text" => HTML.escape(translate(locale, "Replies loaded")), "preferences" => env.get("preferences").as(Preferences) }.to_pretty_json %> diff --git a/src/invidious/views/post.ecr b/src/invidious/views/post.ecr index fb03a44c..07f96529 100644 --- a/src/invidious/views/post.ecr +++ b/src/invidious/views/post.ecr @@ -35,6 +35,7 @@ "comments_text" => HTML.escape(translate(locale, "View `x` comments", "{commentCount}")), "hide_replies_text" => HTML.escape(translate(locale, "Hide replies")), "show_replies_text" => HTML.escape(translate(locale, "Show replies")), + "replies_loaded_text" => HTML.escape(translate(locale, "Replies loaded")), "params" => { "comments": ["youtube"] }, diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 6f9ced6f..1d2377a7 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -59,6 +59,7 @@ we're going to need to do it here in order to allow for translations. "comments_text" => HTML.escape(translate(locale, "View `x` comments", "{commentCount}")), "hide_replies_text" => HTML.escape(translate(locale, "Hide replies")), "show_replies_text" => HTML.escape(translate(locale, "Show replies")), + "replies_loaded_text" => HTML.escape(translate(locale, "Replies loaded")), "params" => params, "preferences" => preferences, "premiere_timestamp" => video.premiere_timestamp.try &.to_unix, @@ -158,7 +159,7 @@ we're going to need to do it here in order to allow for translations. <% if user %> <% playlists = Invidious::Database::Playlists.select_user_created_playlists(user.email) %> <% if !playlists.empty? %> -
+
"> +