Commit 76b5f3d7 authored by Max's avatar Max
Browse files

Bug 1762085 - Add video wrapper with subtitle support for funimation.com. r=niklas,kpatenio

parent 6c12fecd
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -36,6 +36,12 @@ let AVAILABLE_PIP_OVERRIDES;
      },
    },

    funimation: {
      "https://*.funimation.com/*": {
        videoWrapperScriptPath: "video-wrappers/funimation.js",
      },
    },

    instagram: {
      "https://www.instagram.com/*": { policy: TOGGLE_POLICIES.ONE_QUARTER },
    },
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ FINAL_TARGET_FILES.features["pictureinpicture@mozilla.org"]["lib"] += [
]

FINAL_TARGET_FILES.features["pictureinpicture@mozilla.org"]["video-wrappers"] += [
    "video-wrappers/funimation.js",
    "video-wrappers/mock-wrapper.js",
    "video-wrappers/netflix.js",
    "video-wrappers/primeVideo.js",
+41 −0
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

class PictureInPictureVideoWrapper {
  setCaptionContainerObserver(video, updateCaptionsFunction) {
    let container = document.getElementById("vjs_video_3");

    if (container) {
      updateCaptionsFunction("");
      const callback = function(mutationsList, observer) {
        let textNodeList = container
          .querySelector(".vjs-text-track-cue")
          ?.querySelectorAll("div");
        if (!textNodeList) {
          updateCaptionsFunction("");
          return;
        }

        updateCaptionsFunction(
          Array.from(textNodeList, x => x.textContent).join("\n")
        );
      };

      // immediately invoke the callback function to add subtitles to the PiP window
      callback([1], null);

      let captionsObserver = new MutationObserver(callback);

      captionsObserver.observe(container, {
        attributes: false,
        childList: true,
        subtree: true,
      });
    }
  }
}

this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;