tor-browser

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

jwplayerWrapper.js (1172B)


      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 JWPlayer
      8 class PictureInPictureVideoWrapper {
      9  setCaptionContainerObserver(video, updateCaptionsFunction) {
     10    let container = document.querySelector(".jw-captions");
     11 
     12    if (container) {
     13      updateCaptionsFunction("");
     14 
     15      const callback = function () {
     16        let text = container.innerText;
     17        if (!text) {
     18          updateCaptionsFunction("");
     19          return;
     20        }
     21 
     22        updateCaptionsFunction(text);
     23      };
     24 
     25      // immediately invoke the callback function to add subtitles to the PiP window
     26      callback();
     27 
     28      this.captionsObserver = new MutationObserver(callback);
     29 
     30      this.captionsObserver.observe(container, {
     31        attributes: false,
     32        childList: true,
     33        subtree: true,
     34      });
     35    }
     36  }
     37 
     38  removeCaptionContainerObserver() {
     39    this.captionsObserver?.disconnect();
     40  }
     41 }
     42 
     43 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;