canalplus.js (1647B)
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 isLive() { 9 let documentURI = document.documentURI; 10 return documentURI.includes("/live/") || documentURI.includes("/TV/"); 11 } 12 13 getDuration(video) { 14 if (this.isLive(video)) { 15 return Infinity; 16 } 17 return video.duration; 18 } 19 20 setCaptionContainerObserver(video, updateCaptionsFunction) { 21 let container = 22 document.querySelector(`[data-testid="playerRoot"]`) || 23 document.querySelector(`[player-root="true"]`); 24 25 if (container) { 26 updateCaptionsFunction(""); 27 const callback = function (mutationsList) { 28 // eslint-disable-next-line no-unused-vars 29 for (const mutation of mutationsList) { 30 let text = container.querySelector( 31 ".rxp-texttrack-region" 32 )?.innerText; 33 if (!text) { 34 updateCaptionsFunction(""); 35 return; 36 } 37 38 updateCaptionsFunction(text); 39 } 40 }; 41 42 // immediately invoke the callback function to add subtitles to the PiP window 43 callback([1], null); 44 45 this.captionsObserver = new MutationObserver(callback); 46 47 this.captionsObserver.observe(container, { 48 attributes: false, 49 childList: true, 50 subtree: true, 51 }); 52 } 53 } 54 55 removeCaptionContainerObserver() { 56 this.captionsObserver?.disconnect(); 57 } 58 } 59 60 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;