disneyplus.js (2064B)
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 // Handle Disney+ (US) 10 let container = document.querySelector(".TimedTextOverlay"); 11 12 if (container) { 13 const callback = () => { 14 let textNodeList = container.querySelectorAll( 15 ".hive-subtitle-renderer-line" 16 ); 17 18 if (!textNodeList.length) { 19 updateCaptionsFunction(""); 20 return; 21 } 22 23 updateCaptionsFunction( 24 Array.from(textNodeList, x => x.textContent).join("\n") 25 ); 26 }; 27 28 // immediately invoke the callback function to add subtitles to the PiP window 29 callback(); 30 31 this.captionsObserver = new MutationObserver(callback); 32 this.captionsObserver.observe(container, { 33 attributes: false, 34 childList: true, 35 subtree: true, 36 }); 37 return; 38 } 39 40 // Handle Disney+ (non US version) 41 container = document.querySelector(".shaka-text-container"); 42 if (container) { 43 updateCaptionsFunction(""); 44 const callback = function () { 45 let textNodeList = container?.querySelectorAll("span"); 46 if (!textNodeList) { 47 updateCaptionsFunction(""); 48 return; 49 } 50 51 updateCaptionsFunction( 52 Array.from(textNodeList, x => x.textContent).join("\n") 53 ); 54 }; 55 56 // immediately invoke the callback function to add subtitles to the PiP window 57 callback([1], null); 58 59 this.captionsObserver = new MutationObserver(callback); 60 61 this.captionsObserver.observe(container, { 62 attributes: false, 63 childList: true, 64 subtree: true, 65 }); 66 } 67 } 68 69 removeCaptionContainerObserver() { 70 this.captionsObserver?.disconnect(); 71 } 72 } 73 74 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;