tubi.js (1136B)
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(`[data-id="hls"]`); 10 11 if (container) { 12 updateCaptionsFunction(""); 13 const callback = function () { 14 let text = container?.querySelector( 15 `[data-id="captionsComponent"]:not([style="display: none;"])` 16 )?.innerText; 17 18 updateCaptionsFunction(text); 19 }; 20 21 // immediately invoke the callback function to add subtitles to the PiP window 22 callback([1], null); 23 24 this.captionsObserver = new MutationObserver(callback); 25 26 this.captionsObserver.observe(container, { 27 attributes: true, 28 childList: true, 29 subtree: true, 30 }); 31 } 32 } 33 34 removeCaptionContainerObserver() { 35 this.captionsObserver?.disconnect(); 36 } 37 } 38 39 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;