hulu.js (2261B)
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 constructor(video) { 9 this.player = video.wrappedJSObject.__HuluDashPlayer__; 10 } 11 12 play() { 13 this.player.play(); 14 } 15 16 pause() { 17 this.player.pause(); 18 } 19 20 isMuted(video) { 21 return video.volume === 0; 22 } 23 24 setMuted(video, shouldMute) { 25 let muteButton = document.querySelector(".VolumeControl > div"); 26 27 if (this.isMuted(video) !== shouldMute) { 28 muteButton.click(); 29 } 30 } 31 32 setCurrentTime(video, position) { 33 this.player.currentTime = position; 34 } 35 36 setCaptionContainerObserver(video, updateCaptionsFunction) { 37 let container = document.querySelector(".ClosedCaption"); 38 39 if (container) { 40 updateCaptionsFunction(""); 41 const callback = function () { 42 // This will get the subtitles for both live and regular playback videos 43 // and combine them to display. liveVideoText should be an empty string 44 // when the video is regular playback and vice versa. If both 45 // liveVideoText and regularVideoText are non empty strings, which 46 // doesn't seem to be the case, they will both show. 47 let liveVideoText = Array.from( 48 container.querySelectorAll( 49 "#inband-closed-caption > div > div > div" 50 ), 51 x => x.textContent.trim() 52 ) 53 .filter(String) 54 .join("\n"); 55 let regularVideoText = container.querySelector(".CaptionBox").innerText; 56 57 updateCaptionsFunction(liveVideoText + regularVideoText); 58 }; 59 60 // immediately invoke the callback function to add subtitles to the PiP window 61 callback([1], null); 62 63 this.captionsObserver = new MutationObserver(callback); 64 65 this.captionsObserver.observe(container, { 66 attributes: false, 67 childList: true, 68 subtree: true, 69 }); 70 } 71 } 72 73 removeCaptionContainerObserver() { 74 this.captionsObserver?.disconnect(); 75 } 76 77 getDuration() { 78 return this.player.duration; 79 } 80 } 81 82 this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;