11import { videosettings , ytvideo } from "../../_shared" ;
2- import { c , getBrowserInstance , injectScript } from "../../_sharedBrowser" ;
2+ import { c , getBrowserInstance , injectScript , isChrome } from "../../_sharedBrowser" ;
33import iconWatchLater from "./../../../icons/watchlater.svg" ;
44import { addToStore , enqueue , enqueueNow , gotoNextInQueue , init as initQueue , isEmptyQueue , setQueue , videoUrlMatch } from "./_queue" ;
55import { init as initDrag } from "./_queueDrag" ;
@@ -26,7 +26,7 @@ export const nebula = async () => {
2626
2727 const isAndroid : boolean = await getBrowserInstance ( ) . runtime . sendMessage ( "isAndroid" ) ;
2828 const { youtube, theatre, customScriptPage } = await getFromStorage ( { youtube : false , theatre : false , customScriptPage : '' } ) ;
29- console . debug ( youtube , theatre ) ;
29+ console . debug ( 'Youtube:' , youtube , 'Theatre Mode:' , theatre , 'Video page?' , isVideoPage ( ) ) ;
3030 theatreMode = theatre ;
3131
3232 const r = refreshTheatreMode . bind ( null , menu ) ;
@@ -36,9 +36,7 @@ export const nebula = async () => {
3636 Array . from ( document . querySelectorAll < HTMLImageElement > ( `${ videoselector } img` ) ) . forEach ( createLink ) ;
3737 if ( youtube )
3838 maybeLoadComments ( ) ;
39- cancelTheatreMode ( ) ;
40- if ( ! isAndroid )
41- updateTheatreMode ( menu ) ;
39+ domRefreshTheatreMode ( isAndroid , menu ) ;
4240 const f = document . querySelector ( 'iframe' ) ;
4341 if ( ! f ) return ;
4442 f . removeEventListener ( 'fullscreenchange' , r ) ;
@@ -47,7 +45,7 @@ export const nebula = async () => {
4745 } ) ;
4846 const m = new MutationObserver ( cb ) ;
4947 m . observe ( document . querySelector ( '#root' ) , { subtree : true , childList : true } ) ;
50- window . addEventListener ( 'resize' , ( ) => updateTheatreMode ( menu ) ) ;
48+ window . addEventListener ( 'resize' , updateTheatreMode . bind ( null , menu ) ) ;
5149 cb ( ) ;
5250
5351 // inject custom script (if available)
@@ -115,10 +113,10 @@ const createLink = (img: HTMLElement) => {
115113} ;
116114const mutation = ( func : ( ) => void ) => {
117115 let timeout = 0 ;
118- return function ( ) {
116+ return ( ) => {
119117 clearTimeout ( timeout ) ;
120118 timeout = window . setTimeout ( func , 500 ) ;
121- }
119+ } ;
122120} ;
123121
124122const click = async ( e : MouseEvent ) => {
@@ -170,7 +168,8 @@ const loadComments = async () => {
170168 const title = h2 [ 0 ] . textContent ;
171169 const creator = h2 [ 1 ] . textContent ;
172170 if ( ! title || ! creator ) return ;
173- if ( ! h2 [ 0 ] . nextElementSibling || h2 [ 0 ] . nextElementSibling . querySelector ( '.enhancer-yt' ) )
171+ const e = h2 [ 0 ] . nextElementSibling ;
172+ if ( ! e || e . querySelector ( '.enhancer-yt' ) )
174173 return ; // already requested
175174 console . debug ( `Requesting '${ title } ' by ${ creator } ` ) ;
176175
@@ -183,10 +182,11 @@ const loadComments = async () => {
183182 a . target = '_blank' ;
184183 a . textContent = a . href ;
185184 v . append ( a , ` (${ ( vid . confidence * 100 ) . toFixed ( 1 ) } %)` ) ;
186- h2 [ 0 ] . nextElementSibling . append ( h2 [ 0 ] . nextElementSibling . querySelector ( 'span[class]' ) ?. cloneNode ( true ) , v ) ; // dot
185+ e . append ( e . querySelector ( 'span[class]' ) ?. cloneNode ( true ) , v ) ; // dot
187186 } catch ( err ) {
188187 console . error ( err ) ;
189188 }
189+ console . debug ( 'Loading comments done.' ) ;
190190} ;
191191
192192const maybeGoTheatreMode = ( menu : HTMLElement ) => {
@@ -196,6 +196,8 @@ const maybeGoTheatreMode = (menu: HTMLElement) => {
196196const goTheatreMode = ( menu : HTMLElement ) => {
197197 const mh = menu . getBoundingClientRect ( ) . height ;
198198 const frame = document . querySelector ( 'iframe' ) ;
199+ if ( ! frame )
200+ return ;
199201 const ratio = frame . clientWidth / frame . clientHeight ;
200202 const top = + window . getComputedStyle ( frame . parentElement . parentElement ) . paddingTop . slice ( 0 , - 2 ) ;
201203 if ( ! ratio )
@@ -226,11 +228,24 @@ const updateTheatreMode = (menu: HTMLElement) => {
226228 maybeGoTheatreMode ( menu ) ;
227229} ;
228230const refreshTheatreMode = ( menu : HTMLElement ) => {
229- if ( ! theatreMode )
231+ if ( ! theatreMode || ! isVideoPage ( ) )
230232 return ;
231233 cancelTheatreMode ( ) ;
232234 setTimeout ( goTheatreMode , 0 , menu ) ;
233235} ;
236+ const domRefreshTheatreMode = ( ( ) => {
237+ let hadIFrame = false ;
238+ return ( isAndroid : boolean , menu : HTMLElement ) => {
239+ if ( isAndroid )
240+ return ;
241+ const hasIFrame = document . querySelector ( 'iframe' ) ;
242+ if ( ! hadIFrame && hasIFrame )
243+ refreshTheatreMode ( menu ) ;
244+ if ( theatreMode && ! hasIFrame . style . height )
245+ goTheatreMode ( menu ) ;
246+ hadIFrame = ! ! hasIFrame ;
247+ } ;
248+ } ) ( ) ;
234249
235250const focusIframe = ( iter = 0 ) => {
236251 if ( ! isVideoPage ( ) ) return ;
0 commit comments