summaryrefslogtreecommitdiffstats
path: root/assets/js
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2023-10-21 13:45:15 +0200
committerSamantaz Fox <coding@samantaz.fr>2023-10-21 13:45:15 +0200
commit40919c6a83c78b890b7974304110c10b30a3746a (patch)
tree99e240adfd7aa09a2788ec68841025f5a4e9022f /assets/js
parent47cc9dc169595af77f4fdd740d83479d5d111f43 (diff)
downloadinvidious-40919c6a83c78b890b7974304110c10b30a3746a.tar.gz
invidious-40919c6a83c78b890b7974304110c10b30a3746a.tar.bz2
invidious-40919c6a83c78b890b7974304110c10b30a3746a.zip
JS: Update external links exactly once per second
Diffstat (limited to 'assets/js')
-rw-r--r--assets/js/player.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/assets/js/player.js b/assets/js/player.js
index c34da9b5..16bb2752 100644
--- a/assets/js/player.js
+++ b/assets/js/player.js
@@ -115,11 +115,22 @@ function addCurrentTimeToURL(url, base) {
}
/**
+ * Global variable to save the last timestamp (in full seconds) at which the external
+ * links were updated by the 'timeupdate' callback below.
+ *
+ * It is initialized to 5s so that the video will always restart from the beginning
+ * if the user hasn't really started watching before switching to the other website.
+ */
+var timeupdate_last_ts = 5;
+
+/**
* Callback that updates the timestamp on all external links
*/
player.on('timeupdate', function () {
- // Only update once every 5 seconds
- if ((Math.ceil(player.currentTime()) % 5) != 0) return;
+ // Only update once every second
+ let current_ts = Math.floor(player.currentTime());
+ if (current_ts > timeupdate_last_ts) timeupdate_last_ts = current_ts;
+ else return;
// YouTube links