nytimes.js (1163B)
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(".react-vhs-player"); 10 11 if (container) { 12 updateCaptionsFunction(""); 13 const callback = function () { 14 let text = container.querySelector(".cueWrap-2P4Ue4VQ")?.innerText; 15 if (!text) { 16 updateCaptionsFunction(""); 17 return; 18 } 19 20 updateCaptionsFunction(text); 21 }; 22 23 // immediately invoke the callback function to add subtitles to the PiP window 24 callback([1], null); 25 26 this.captionsObserver = new MutationObserver(callback); 27 28 this.captionsObserver.observe(container, { 29 attributes: false, 30 childList: true, 31 subtree: true, 32 }); 33 } 34 } 35 36 removeCaptionContainerObserver() { 37 this.captionsObserver?.disconnect(); 38 } 39 } 40 41 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;