From 9979a1b9101c13e9c86ffa94f8e3722ebf70b71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9ry=20Mathieu=20=28Mathius=29?= Date: Sat, 19 Feb 2022 17:03:22 +0100 Subject: [PATCH 1/4] Add currentTimestamp in shared url by videojs-share --- assets/js/player.js | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/assets/js/player.js b/assets/js/player.js index 81a27009..42f00ef7 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -35,21 +35,11 @@ if (player_data.aspect_ratio) { var embed_url = new URL(location); embed_url.searchParams.delete('v'); -short_url = location.origin + '/' + video_data.id + embed_url.search; +var short_url = location.origin + '/' + video_data.id + embed_url.search; embed_url = location.origin + '/embed/' + video_data.id + embed_url.search; var save_player_pos_key = "save_player_pos"; -var shareOptions = { - socials: ['fbFeed', 'tw', 'reddit', 'email'], - - url: short_url, - title: player_data.title, - description: player_data.description, - image: player_data.thumbnail, - embedCode: "" -} - videojs.Vhs.xhr.beforeRequest = function(options) { if (options.uri.indexOf('videoplayback') === -1 && options.uri.indexOf('local=true') === -1) { options.uri = options.uri + '?local=true'; @@ -59,6 +49,38 @@ videojs.Vhs.xhr.beforeRequest = function(options) { var player = videojs('player', options); +/** + * Function for add time argument to url + * @param {String} url + * @returns urlWithTimeArg + */ +function addCurrentTimeToURL(url) { + var urlUsed = new URL(url); + urlUsed.searchParams.delete('start'); + var currentTime = Math.ceil(player.currentTime()); + if (currentTime > 0) + urlUsed.searchParams.set('t', currentTime); + else + if (urlUsed.searchParams.has('t')) + urlUsed.searchParams.delete('t'); + return urlUsed; +} + +var shareOptions = { + socials: ['fbFeed', 'tw', 'reddit', 'email'], + + get url() { + return addCurrentTimeToURL(short_url); + }, + title: player_data.title, + description: player_data.description, + image: player_data.thumbnail, + get embedCode() { + return ""; + } +}; + const storage = (() => { try { if (localStorage.length !== -1) return localStorage; } catch (e) { console.info('No storage available: ' + e); } From d77586d02d6b22a3568da501ab8cb22f87afdc41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9ry=20Mathieu=20=28Mathius=29?= Date: Tue, 22 Feb 2022 00:21:47 +0100 Subject: [PATCH 2/4] Remove extra space in shareOptions.embedCode of player script Follow lint indications : https://github.com/iv-org/invidious/pull/2912#discussion_r811367117 --- assets/js/player.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/player.js b/assets/js/player.js index 42f00ef7..eed26e5c 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -77,7 +77,7 @@ var shareOptions = { image: player_data.thumbnail, get embedCode() { return ""; + addCurrentTimeToURL(embed_url) + "' style='border:none;'>"; } }; From 36c7d4270b8bc46c555b92539628bbbe4f49cc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9ry=20Mathieu=20=28Mathius=29?= Date: Tue, 22 Feb 2022 00:27:00 +0100 Subject: [PATCH 3/4] Lint conditional deletion of t in addCurrentTimeToURL inside player script Follow lint indications : https://github.com/iv-org/invidious/pull/2912#discussion_r811474927 --- assets/js/player.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/assets/js/player.js b/assets/js/player.js index eed26e5c..f0b616a0 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -60,9 +60,8 @@ function addCurrentTimeToURL(url) { var currentTime = Math.ceil(player.currentTime()); if (currentTime > 0) urlUsed.searchParams.set('t', currentTime); - else - if (urlUsed.searchParams.has('t')) - urlUsed.searchParams.delete('t'); + else if (urlUsed.searchParams.has('t')) + urlUsed.searchParams.delete('t'); return urlUsed; } From 31699468fc23b9bbfd607cb900cec7d65e69b8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9ry=20Mathieu=20=28Mathius=29?= Date: Tue, 22 Feb 2022 00:44:36 +0100 Subject: [PATCH 4/4] Lint docs of addCurrentTimeToURL in player script Follow lint indications : https://github.com/iv-org/invidious/pull/2912#discussion_r811479583 --- assets/js/player.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/player.js b/assets/js/player.js index f0b616a0..a1a2cd16 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -51,7 +51,7 @@ var player = videojs('player', options); /** * Function for add time argument to url - * @param {String} url + * @param {String} url * @returns urlWithTimeArg */ function addCurrentTimeToURL(url) {