From 792a999386f9147233d26300856a5802da5fc8c1 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 14 Sep 2023 20:39:46 +0200 Subject: [PATCH] Frontend: Add timestamp on youtube+embed links --- assets/js/player.js | 15 +++++++++++++++ src/invidious/views/watch.ecr | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/assets/js/player.js b/assets/js/player.js index bb53ac24..cd0e7a72 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -112,6 +112,21 @@ function addCurrentTimeToURL(url) { return urlUsed; } +/** + * Timer that updates the timestamp on "watch on youtube" and "embed" links + */ +player.ready(function () { + let elem_watch = document.getElementById('link-yt-watch'); + let elem_embed = document.getElementById('link-yt-embed'); + + let base_url_watch = elem_watch.getAttribute('data-base-url'); + let base_url_embed = elem_embed.getAttribute('data-base-url'); + + setTimeout(() => { elem_watch.setAttribute('href') = addCurrentTimeToURL(base_url_watch); }, 5000); + setTimeout(() => { elem_embed.setAttribute('href') = addCurrentTimeToURL(base_url_embed); }, 5000); +}); + + var shareOptions = { socials: ['fbFeed', 'tw', 'reddit', 'email'], diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 498d57a1..ac3fee65 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -112,8 +112,18 @@ we're going to need to do it here in order to allow for translations.
- <%= translate(locale, "videoinfo_watch_on_youTube") %> - (<%= translate(locale, "videoinfo_youTube_embed_link") %>) + <%- + link_yt_watch = URI.new(scheme: "https", host: "www.youtube.com", path: "/watch", query: "v=#{video.id}") + link_yt_embed = URI.new(scheme: "https", host: "www.youtube.com", path: "/embed/#{video.id}") + + if !plid.nil? && !continuation.nil? + link_yt_param = URI::Params{"plid" => [plid], "index" => [continuation.to_s]} + link_yt_watch = IV::HttpServer::Utils.add_params_to_url(link_yt_watch, link_yt_param) + link_yt_embed = IV::HttpServer::Utils.add_params_to_url(link_yt_embed, link_yt_param) + end + -%> + <%= translate(locale, "videoinfo_watch_on_youTube") %> + (<%= translate(locale, "videoinfo_youTube_embed_link") %>)

<% if env.get("preferences").as(Preferences).automatic_instance_redirect%>