tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

videojsWrapper.js (1077B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 // This wrapper supports multiple sites that use video.js player
      8 class PictureInPictureVideoWrapper {
      9  setCaptionContainerObserver(video, updateCaptionsFunction) {
     10    let container = document.querySelector(".vjs-text-track-display");
     11 
     12    if (container) {
     13      updateCaptionsFunction("");
     14      const callback = function () {
     15        let text = container.textContent;
     16 
     17        updateCaptionsFunction(text);
     18      };
     19 
     20      // immediately invoke the callback function to add subtitles to the PiP window
     21      callback();
     22 
     23      this.captionsObserver = new MutationObserver(callback);
     24 
     25      this.captionsObserver.observe(container, {
     26        childList: true,
     27        subtree: true,
     28      });
     29    }
     30  }
     31 
     32  removeCaptionContainerObserver() {
     33    this.captionsObserver?.disconnect();
     34  }
     35 }
     36 
     37 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;