piped.js (1323B)
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(".player-container"); 10 11 if (container) { 12 updateCaptionsFunction(""); 13 const callback = function () { 14 let textNodeList = container 15 .querySelector(".shaka-text-wrapper") 16 ?.querySelectorAll('span[style="background-color: black;"]'); 17 if (!textNodeList) { 18 updateCaptionsFunction(""); 19 return; 20 } 21 22 updateCaptionsFunction( 23 Array.from(textNodeList, x => x.textContent).join("\n") 24 ); 25 }; 26 27 // immediately invoke the callback function to add subtitles to the PiP window 28 callback([1], null); 29 30 this.captionsObserver = new MutationObserver(callback); 31 32 this.captionsObserver.observe(container, { 33 attributes: false, 34 childList: true, 35 subtree: true, 36 }); 37 } 38 } 39 40 removeCaptionContainerObserver() { 41 this.captionsObserver?.disconnect(); 42 } 43 } 44 45 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;