tor-browser

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

udemy.js (1751B)


      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 class PictureInPictureVideoWrapper {
      8  play(video) {
      9    let playPauseButton = document.querySelector(
     10      `[data-purpose="play-button"]`
     11    );
     12    if (video.paused) {
     13      playPauseButton?.click();
     14    }
     15  }
     16 
     17  pause(video) {
     18    let playPauseButton = document.querySelector(
     19      `[data-purpose="pause-button"]`
     20    );
     21    if (!video.paused) {
     22      playPauseButton?.click();
     23    }
     24  }
     25 
     26  setMuted(video, shouldMute) {
     27    let muteButton = document.querySelector(
     28      `[data-purpose="volume-control-button"]`
     29    );
     30    if (video.muted !== shouldMute && muteButton) {
     31      muteButton.click();
     32    }
     33  }
     34 
     35  setCaptionContainerObserver(video, updateCaptionsFunction) {
     36    let container = video.parentElement;
     37 
     38    if (container) {
     39      updateCaptionsFunction("");
     40      const callback = function () {
     41        let text = container.querySelector(
     42          `[data-purpose="captions-cue-text"]`
     43        )?.innerText;
     44        if (!text) {
     45          updateCaptionsFunction("");
     46          return;
     47        }
     48 
     49        updateCaptionsFunction(text);
     50      };
     51 
     52      // immediately invoke the callback function to add subtitles to the PiP window
     53      callback([1], null);
     54 
     55      this.captionsObserver = new MutationObserver(callback);
     56 
     57      this.captionsObserver.observe(container, {
     58        attributes: true,
     59        childList: true,
     60        subtree: true,
     61      });
     62    }
     63  }
     64  removeCaptionContainerObserver() {
     65    this.captionsObserver?.disconnect();
     66  }
     67 }
     68 
     69 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;