joyn.js (1054B)
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( 10 "#trackable-player-element > article" 11 ); 12 13 if (container) { 14 const callback = () => { 15 let text = container.querySelector( 16 `:scope > div > div > div > div[role="cue"]` 17 )?.innerText; 18 if (!text) { 19 updateCaptionsFunction(""); 20 return; 21 } 22 23 updateCaptionsFunction(text); 24 }; 25 26 callback(); 27 28 this.captionsObserver = new MutationObserver(callback); 29 30 this.captionsObserver.observe(container, { 31 childList: true, 32 }); 33 } 34 } 35 36 removeCaptionContainerObserver() { 37 this.captionsObserver?.disconnect(); 38 } 39 } 40 41 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;