Add logic to show/hide transcripts without JS

This commit is contained in:
syeopite 2024-06-12 10:23:48 -07:00
parent 654f5fd45e
commit 786e40afb0
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
3 changed files with 23 additions and 2 deletions

View File

@ -503,5 +503,7 @@
"carousel_skip": "Skip the Carousel", "carousel_skip": "Skip the Carousel",
"carousel_go_to": "Go to slide `x`", "carousel_go_to": "Go to slide `x`",
"video_description_show_transcript_section_label": "Transcripts", "video_description_show_transcript_section_label": "Transcripts",
"video_description_show_transcript_section_button": "Show transcript" "video_description_show_transcript_section_button": "Show transcript",
"video_description_show_transcript_section_button_hide": "Hide transcript",
"error_transcripts_none_available": "No transcripts are available"
} }

View File

@ -38,6 +38,11 @@ module Invidious::Routes::Watch
nojs ||= "0" nojs ||= "0"
nojs = nojs == "1" nojs = nojs == "1"
show_transcripts = env.params.query["show_transcripts"]?
show_transcripts ||= "0"
show_transcripts = show_transcripts == "1"
preferences = env.get("preferences").as(Preferences) preferences = env.get("preferences").as(Preferences)
user = env.get?("user").try &.as(User) user = env.get?("user").try &.as(User)
@ -156,6 +161,13 @@ module Invidious::Routes::Watch
} }
captions = captions - preferred_captions captions = captions - preferred_captions
if show_transcripts
# Placeholder
transcript = true
else
transcript = nil
end
aspect_ratio = "16:9" aspect_ratio = "16:9"
thumbnail = "/vi/#{video.id}/maxres.jpg" thumbnail = "/vi/#{video.id}/maxres.jpg"

View File

@ -260,7 +260,14 @@ we're going to need to do it here in order to allow for translations.
<% if captions %> <% if captions %>
<div class="description-widget description-show-transcript-widget"> <div class="description-widget description-show-transcript-widget">
<h4><%=HTML.escape(translate(locale, "video_description_show_transcript_section_label"))%></h4> <h4><%=HTML.escape(translate(locale, "video_description_show_transcript_section_label"))%></h4>
<a class="pure-button pure-button-secondary"><%=HTML.escape(translate(locale, "video_description_show_transcript_section_button"))%></a> <% if transcript %>
<% hide_transcripts_param = env.params.query.dup %>
<% hide_transcripts_param.delete_all("show_transcripts") %>
<a class="pure-button pure-button-secondary" href="/watch?<%= hide_transcripts_param %>"><%=HTML.escape(translate(locale, "video_description_show_transcript_section_button_hide"))%></a>
<% else %>
<a class="pure-button pure-button-secondary" href="/watch?<%= env.params.query %>&show_transcripts=1"><%=HTML.escape(translate(locale, "video_description_show_transcript_section_button"))%></a>
<% end %>
</div> </div>
<% end %> <% end %>
</div> </div>