From 58f4a012b7fde782a83d6745f18c5d080f7ade6a Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 14 Sep 2023 22:10:02 +0200 Subject: [PATCH] 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 d07d6cf44..bffc7ad3b 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 a768328a6..bf297a439 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") %>