From 7214fdaff4b21df7f83c7ab0b51d5ef23415aa0a Mon Sep 17 00:00:00 2001 From: PMK <355176+PMK@users.noreply.github.com> Date: Sat, 6 Jul 2024 21:39:00 +0200 Subject: [PATCH] JS: Update timeupdate event defensive to prevent errors --- assets/js/player.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/assets/js/player.js b/assets/js/player.js index 71c5e7da..8f484c7e 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -135,26 +135,32 @@ player.on('timeupdate', function () { // YouTube links let elem_yt_watch = document.getElementById('link-yt-watch'); + if (elem_yt_watch) { + let base_url_yt_watch = elem_yt_watch.getAttribute('data-base-url'); + elem_yt_watch.href = addCurrentTimeToURL(base_url_yt_watch); + } + let elem_yt_embed = document.getElementById('link-yt-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'); - - elem_yt_watch.href = addCurrentTimeToURL(base_url_yt_watch); - elem_yt_embed.href = addCurrentTimeToURL(base_url_yt_embed); + if (elem_yt_embed) { + let base_url_yt_embed = elem_yt_embed.getAttribute('data-base-url'); + elem_yt_embed.href = addCurrentTimeToURL(base_url_yt_embed); + } // Invidious links let domain = window.location.origin; let elem_iv_embed = document.getElementById('link-iv-embed'); + if (elem_iv_embed) { + let base_url_iv_embed = elem_iv_embed.getAttribute('data-base-url'); + elem_iv_embed.href = addCurrentTimeToURL(base_url_iv_embed, domain); + } + 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'); - - elem_iv_embed.href = addCurrentTimeToURL(base_url_iv_embed, domain); - elem_iv_other.href = addCurrentTimeToURL(base_url_iv_other, domain); + if (elem_iv_other) { + let base_url_iv_other = elem_iv_other.getAttribute('data-base-url'); + elem_iv_other.href = addCurrentTimeToURL(base_url_iv_other, domain); + } });