tor-browser

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

washingtonpost.js (1364B)


      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  setCaptionContainerObserver(video, updateCaptionsFunction) {
      9    let container = document.querySelector(".powa");
     10 
     11    if (container) {
     12      updateCaptionsFunction("");
     13      const callback = function () {
     14        let subtitleElement = container.querySelector(".powa-sub-torpedo");
     15        if (!subtitleElement?.innerText) {
     16          updateCaptionsFunction("");
     17          return;
     18        }
     19        let subtitleElementClone = subtitleElement.cloneNode(true);
     20        let breaks = subtitleElementClone.getElementsByTagName("br");
     21        for (const element of breaks) {
     22          element.replaceWith("\n");
     23        }
     24        let text = subtitleElementClone.innerText;
     25 
     26        updateCaptionsFunction(text);
     27      };
     28 
     29      callback([1], null);
     30 
     31      this.captionsObserver = new MutationObserver(callback);
     32 
     33      this.captionsObserver.observe(container, {
     34        attributes: false,
     35        childList: true,
     36        subtree: true,
     37      });
     38    }
     39  }
     40 
     41  removeCaptionContainerObserver() {
     42    this.captionsObserver?.disconnect();
     43  }
     44 }
     45 
     46 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;