Don't use generic click handler for chapter widget

This commit is contained in:
syeopite 2024-01-22 00:06:27 -08:00
parent 93a6464bbe
commit f48aa0a2c2
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
2 changed files with 13 additions and 7 deletions

View File

@ -191,3 +191,9 @@ addEventListener('load', function (e) {
comments.innerHTML = ''; comments.innerHTML = '';
} }
}); });
const chapter_widget_buttons = document.getElementsByClassName("chapter-widget-buttons")
Array.from(chapter_widget_buttons).forEach(e => e.addEventListener("click", function (event) {
event.preventDefault();
player.currentTime(e.getAttribute('data-jump-time'));
}))

View File

@ -10,21 +10,21 @@
<div class="description-chapters-content-container"> <div class="description-chapters-content-container">
<% chapters.each do | chapter | %> <% chapters.each do | chapter | %>
<%- start_in_seconds = chapter.start_ms.total_seconds.to_i %> <%- start_in_seconds = chapter.start_ms.total_seconds.to_i %>
<a href="/watch?v=<%-= video.id %>&t=<%=start_in_seconds %>"> <a href="/watch?v=<%-= video.id %>&t=<%=start_in_seconds %>" data-jump-time="<%=start_in_seconds%>" class="chapter-widget-buttons">
<div class="chapter" data-onclick="jump_to_time" data-jump-time="<%=start_in_seconds%>"> <div class="chapter">
<div class="thumbnail"> <div class="thumbnail">
<%- if !env.get("preferences").as(Preferences).thin_mode -%> <%- if !env.get("preferences").as(Preferences).thin_mode -%>
<img loading="lazy" class="thumbnail" src="<%-=URI.parse(chapter.thumbnails[-1]["url"].to_s).request_target %>" alt="" data-onclick="jump_to_time" data-jump-time="<%=start_in_seconds%>"/> <img loading="lazy" class="thumbnail" src="<%-=URI.parse(chapter.thumbnails[-1]["url"].to_s).request_target %>" alt="<%=chapter.title%>"/>
<%- else -%> <%- else -%>
<div class="thumbnail-placeholder" data-onclick="jump_to_time" data-jump-time="<%=start_in_seconds%>"></div> <div class="thumbnail-placeholder"></div>
<%- end -%> <%- end -%>
</div> </div>
<%- if start_in_seconds > 0 -%> <%- if start_in_seconds > 0 -%>
<p data-onclick="jump_to_time" data-jump-time="<%=start_in_seconds%>"><%-= recode_length_seconds(start_in_seconds) -%></p> <p><%-= recode_length_seconds(start_in_seconds) -%></p>
<%- else -%> <%- else -%>
<p data-onclick="jump_to_time" data-jump-time="<%=start_in_seconds%>">0:00</p> <p>0:00</p>
<%- end -%> <%- end -%>
<p data-onclick="jump_to_time" data-jump-time="<%=start_in_seconds%>"><%-=chapter.title-%></p> <p><%-=chapter.title-%></p>
</div> </div>
</a> </a>
<% end %> <% end %>