From 792a999386f9147233d26300856a5802da5fc8c1 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 14 Sep 2023 20:39:46 +0200 Subject: [PATCH 1/7] 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%> From 2456b629365450970363e5cf0e9a65c1a24160ab Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 14 Sep 2023 20:50:17 +0200 Subject: [PATCH 2/7] Frontend: Add timestamp on invidious embed links --- assets/js/player.js | 15 +++++++++------ src/invidious/routes/watch.cr | 8 -------- src/invidious/views/watch.ecr | 12 +++++++++++- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/assets/js/player.js b/assets/js/player.js index cd0e7a72..d07d6cf4 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -116,14 +116,17 @@ function addCurrentTimeToURL(url) { * 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 elem_yt_watch = document.getElementById('link-yt-watch'); + let elem_yt_embed = document.getElementById('link-yt-embed'); + let elem_iv_embed = document.getElementById('link-iv-embed'); - let base_url_watch = elem_watch.getAttribute('data-base-url'); - let base_url_embed = elem_embed.getAttribute('data-base-url'); + let base_url_yt_watch = elem_yt_watch.getAttribute('data-base-url'); + let base_url_yt_embed = elem_yt_embed.getAttribute('data-base-url'); + let base_url_iv_embed = elem_iv_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); + setTimeout(() => { elem_yt_watch.setAttribute('href') = addCurrentTimeToURL(base_url_yt_watch); }, 5000); + setTimeout(() => { elem_yt_embed.setAttribute('href') = addCurrentTimeToURL(base_url_yt_embed); }, 5000); + setTimeout(() => { elem_iv_embed.setAttribute('href') = addCurrentTimeToURL(base_url_iv_embed); }, 5000); }); diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index e5cf3716..3d935f0a 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -30,14 +30,6 @@ module Invidious::Routes::Watch return env.redirect "/" end - embed_link = "/embed/#{id}" - if env.params.query.size > 1 - embed_params = HTTP::Params.parse(env.params.query.to_s) - embed_params.delete_all("v") - embed_link += "?" - embed_link += embed_params.to_s - end - plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "") continuation = process_continuation(env.params.query, plid, id) diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index ac3fee65..a768328a 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -125,6 +125,7 @@ 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") %>) +

<% if env.get("preferences").as(Preferences).automatic_instance_redirect%> "><%= translate(locale, "Switch Invidious Instance") %> @@ -132,9 +133,18 @@ we're going to need to do it here in order to allow for translations. <%= translate(locale, "Switch Invidious Instance") %> <% end %>

+ +

<% if params.annotations %> From 58f4a012b7fde782a83d6745f18c5d080f7ade6a Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 14 Sep 2023 22:10:02 +0200 Subject: [PATCH 3/7] Frontend: Add timestamp on switch invidious instance links --- assets/js/player.js | 26 ++++++++++++++++++++------ src/invidious/views/watch.ecr | 7 ++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/assets/js/player.js b/assets/js/player.js index d07d6cf4..bffc7ad3 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -113,20 +113,34 @@ function addCurrentTimeToURL(url) { } /** - * Timer that updates the timestamp on "watch on youtube" and "embed" links + * Timer that updates the timestamp on all external links */ player.ready(function () { + // YouTube links + let elem_yt_watch = document.getElementById('link-yt-watch'); let elem_yt_embed = document.getElementById('link-yt-embed'); - let elem_iv_embed = document.getElementById('link-iv-embed'); let base_url_yt_watch = elem_yt_watch.getAttribute('data-base-url'); let base_url_yt_embed = elem_yt_embed.getAttribute('data-base-url'); - let base_url_iv_embed = elem_iv_embed.getAttribute('data-base-url'); - setTimeout(() => { elem_yt_watch.setAttribute('href') = addCurrentTimeToURL(base_url_yt_watch); }, 5000); - setTimeout(() => { elem_yt_embed.setAttribute('href') = addCurrentTimeToURL(base_url_yt_embed); }, 5000); - setTimeout(() => { elem_iv_embed.setAttribute('href') = addCurrentTimeToURL(base_url_iv_embed); }, 5000); + setTimeout(() => { + elem_yt_watch.setAttribute('href') = addCurrentTimeToURL(base_url_yt_watch); + elem_yt_embed.setAttribute('href') = addCurrentTimeToURL(base_url_yt_embed); + }, 5000); + + // Invidious links + + let elem_iv_embed = document.getElementById('link-iv-embed'); + let elem_iv_other = document.getElementById('link-iv-other'); + + let base_url_iv_embed = elem_iv_embed.getAttribute('data-base-url'); + let base_url_iv_other = elem_iv_other.getAttribute('data-base-url'); + + setTimeout(() => { + elem_iv_embed.setAttribute('href') = addCurrentTimeToURL(base_url_iv_embed); + elem_iv_other.setAttribute('href') = addCurrentTimeToURL(base_url_iv_other); + }, 5000); }); diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index a768328a..bf297a43 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -127,11 +127,8 @@ we're going to need to do it here in order to allow for translations.

- <% if env.get("preferences").as(Preferences).automatic_instance_redirect%> - "><%= translate(locale, "Switch Invidious Instance") %> - <% else %> - <%= translate(locale, "Switch Invidious Instance") %> - <% end %> + <%- link_iv_other = IV::Frontend::Misc.redirect_url(env) -%> + <%= translate(locale, "Switch Invidious Instance") %>