|
|
@@ -4,7 +4,7 @@
|
|
|
function msgPlayEvt(type, target) {
|
|
|
const payload = {
|
|
|
type,
|
|
|
- url: window.location.href,
|
|
|
+ url: PlaylistUtils.cleanVideoUrl(window.location.href),
|
|
|
timestamp: target.currentTime,
|
|
|
duration: target.duration,
|
|
|
title: document.title.replace(/ - YouTube$/, ""),
|
|
|
@@ -12,22 +12,26 @@
|
|
|
return browser.runtime.sendMessage(payload);
|
|
|
}
|
|
|
|
|
|
- const vid = document.querySelector("video");
|
|
|
-
|
|
|
- if (vid) {
|
|
|
- vid.addEventListener("play", function (evt) {
|
|
|
- msgPlayEvt("play", evt.target);
|
|
|
- });
|
|
|
- vid.addEventListener("playing", function (evt) {
|
|
|
- msgPlayEvt("playing", evt.target);
|
|
|
- });
|
|
|
- vid.addEventListener("pause", function (evt) {
|
|
|
- msgPlayEvt("pause", evt.target);
|
|
|
- });
|
|
|
- vid.addEventListener("ended", function (evt) {
|
|
|
- msgPlayEvt("ended", evt.target);
|
|
|
- });
|
|
|
- }
|
|
|
+ // YouTube is a SPA: advancing to the next video in a queue swaps in a new
|
|
|
+ // <video> element without a full page load, so a listener attached to one
|
|
|
+ // specific element (grabbed once at injection time) stops receiving events.
|
|
|
+ // Listening on `document` in the capture phase catches every video, past or
|
|
|
+ // future, while `#movie_player` scopes this to the standard watch-page
|
|
|
+ // player only (excludes home/search hover-preview thumbnails, Shorts, etc).
|
|
|
+ ["play", "playing", "pause", "ended"].forEach(function (type) {
|
|
|
+ document.addEventListener(
|
|
|
+ type,
|
|
|
+ function (evt) {
|
|
|
+ if (
|
|
|
+ evt.target.tagName === "VIDEO" &&
|
|
|
+ evt.target.closest("#movie_player")
|
|
|
+ ) {
|
|
|
+ msgPlayEvt(type, evt.target);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ true,
|
|
|
+ );
|
|
|
+ });
|
|
|
|
|
|
function playIt(tryAgain) {
|
|
|
const video = document.querySelector("video");
|