From e48a000784f685ebfca75fcfc7c06c700839d6f1 Mon Sep 17 00:00:00 2001 From: glmdgrielson Date: Sun, 20 Jan 2019 18:28:28 -0500 Subject: Add annotation player This addresses issue #110 from master. Yay for adding annotations back! --- src/invidious/views/components/player.ecr | 43 +++++++++++++++++++++++ src/invidious/views/components/player_sources.ecr | 3 +- 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecr index 3ab44899..ef434fa3 100644 --- a/src/invidious/views/components/player.ecr +++ b/src/invidious/views/components/player.ecr @@ -213,6 +213,49 @@ if (bpb) { player.httpSourceSelector(); +<% if !params[:listen] %> +var video_container = document.getElementById("player"); +let xhr = new XMLHttpRequest(); +xhr.responseType = "text"; +xhr.timeout = 60000; +xhr.open("GET", "/api/v1/annotations/<%= video.id %>", true); +xhr.send(); + +xhr.onreadystatechange = function () { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + videojs.registerPlugin("youtubeAnnotationsPlugin", youtubeAnnotationsPlugin); + if (!player.paused()) { + player.youtubeAnnotationsPlugin({annotationXml: xhr.response, videoContainer: video_container}); + } else { + player.one('play', function(event) { + player.youtubeAnnotationsPlugin({annotationXml: xhr.response, videoContainer: video_container}); + }); + } + } + } +}; + +window.addEventListener("__ar_annotation_click", e => { + const { url, target, seconds } = e.detail; + + var path = new URL(url); + + if (path.href.startsWith("https://www.youtube.com/watch?") && seconds) { + path.search += "&t=" + seconds; + } + + path = path.pathname + path.search; + + if (target === "current") { + window.location.href = path; + } + else if (target === "new") { + window.open(path, "_blank"); + } +}); +<% end %> + // Since videojs-share can sometimes be blocked, we try to load it last player.share(shareOptions); diff --git a/src/invidious/views/components/player_sources.ecr b/src/invidious/views/components/player_sources.ecr index 37fac6b1..a8b4522b 100644 --- a/src/invidious/views/components/player_sources.ecr +++ b/src/invidious/views/components/player_sources.ecr @@ -2,13 +2,14 @@ + - + <% if params[:quality] != "dash" %> -- cgit v1.2.3