tor-browser

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

airmozilla.js (1722B)


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