dailymotion.js (1568B)
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 = video.closest(".player"); 10 11 if (container) { 12 updateCaptionsFunction(""); 13 const callback = (mutationList = []) => { 14 if (mutationList.length) { 15 let changed = false; 16 for (const mutation of mutationList) { 17 if (mutation.target.matches?.(".subtitles-text")) { 18 changed = true; 19 break; 20 } 21 } 22 23 if (!changed) { 24 return; 25 } 26 } 27 28 let textNodeList = container 29 .querySelector(".subtitles") 30 ?.querySelectorAll("div"); 31 32 if (!textNodeList?.length) { 33 updateCaptionsFunction(""); 34 return; 35 } 36 37 updateCaptionsFunction( 38 Array.from(textNodeList, x => x.innerText).join("\n") 39 ); 40 }; 41 42 // immediately invoke the callback function to add subtitles to the PiP window 43 callback(); 44 45 this.captionsObserver = new MutationObserver(callback); 46 47 this.captionsObserver.observe(container, { 48 childList: true, 49 subtree: true, 50 }); 51 } 52 } 53 54 removeCaptionContainerObserver() { 55 this.captionsObserver?.disconnect(); 56 } 57 } 58 59 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;