@@ -5,17 +5,17 @@ import { ErrorDetection } from './error-detection.js';
55import { appendThumbnailOverlay as showThumbnailOverlay } from './overlays/thumbnail-overlay.js' ;
66import { stopVideoFromPlaying } from './pause-video.js' ;
77import { showError } from './custom-error/custom-error.js' ;
8- import { Logger , SideEffects } from './util.js' ;
8+ import { Logger , SideEffects } from '../duckplayer /util.js' ;
99
1010/**
1111 * @import {DuckPlayerNativeMessages} from './messages.js'
12- * @import {Environment} from './environment.js'
12+ * @import {Environment} from '../duckplayer /environment.js'
1313 * @import {ErrorDetectionSettings} from './error-detection.js'
1414 * @import {DuckPlayerNativeSettings} from "@duckduckgo/privacy-configuration/schema/features/duckplayer-native.js"
1515 */
1616
1717/**
18- * @typedef {(SideEffects, Logger) => void } CustomEventHandler
18+ * @typedef {(effects: SideEffects, logger: Logger) => void } CustomEventHandler
1919 * @typedef {DuckPlayerNativeSettings['selectors'] } DuckPlayerNativeSelectors
2020 */
2121
@@ -32,12 +32,12 @@ export class DuckPlayerNativePage {
3232 messages ;
3333 /**
3434 * Runs when an instance of this class is initialized
35- * @type {CustomEventHandler }
35+ * @type {CustomEventHandler|undefined }
3636 */
3737 onInit ;
3838 /**
3939 * Runs after the current document has been loaded
40- * @type {CustomEventHandler }
40+ * @type {CustomEventHandler|undefined }
4141 */
4242 onLoad ;
4343
@@ -56,8 +56,8 @@ export class DuckPlayerNativePage {
5656
5757 this . setupLogger ( ) ;
5858
59- this . onLoad = onLoad || ( ( ) => { } ) ;
60- this . onInit = onInit || ( ( ) => { } ) ;
59+ this . onLoad = onLoad ;
60+ this . onInit = onInit ;
6161
6262 this . selectors = selectors ;
6363 this . environment = environment ;
@@ -80,13 +80,13 @@ export class DuckPlayerNativePage {
8080
8181 init ( ) {
8282 this . logger . log ( 'Running init handlers' ) ;
83- this . onInit ( this . sideEffects , this . logger ) ;
83+ this . onInit ?. ( this . sideEffects , this . logger ) ;
8484
8585 if ( document . readyState === 'loading' ) {
8686 this . sideEffects . add ( 'setting up load event listener' , ( ) => {
8787 const loadHandler = ( ) => {
8888 this . logger . log ( 'Running deferred load handlers' ) ;
89- this . onLoad ( this . sideEffects , this . logger ) ;
89+ this . onLoad ?. ( this . sideEffects , this . logger ) ;
9090 this . messages . notifyScriptIsReady ( ) ;
9191 } ;
9292 document . addEventListener ( 'DOMContentLoaded' , loadHandler , { once : true } ) ;
@@ -97,7 +97,7 @@ export class DuckPlayerNativePage {
9797 } ) ;
9898 } else {
9999 this . logger . log ( 'Running load handlers immediately' ) ;
100- this . onLoad ( this . sideEffects , this . logger ) ;
100+ this . onLoad ?. ( this . sideEffects , this . logger ) ;
101101 this . messages . notifyScriptIsReady ( ) ;
102102 }
103103 }
@@ -112,6 +112,9 @@ export class DuckPlayerNativePage {
112112 * @param {DuckPlayerNativeMessages } messages
113113 */
114114export function setupDuckPlayerForYouTube ( selectors , playbackPaused , environment , messages ) {
115+ /**
116+ * @type {(sideEffects: SideEffects, logger: Logger, pause: boolean) => void }
117+ */
115118 const mediaControlHandler = ( sideEffects , logger , pause ) => {
116119 logger . log ( 'Running media control handler. Pause:' , pause ) ;
117120
@@ -141,6 +144,7 @@ export function setupDuckPlayerForYouTube(selectors, playbackPaused, environment
141144 }
142145 } ;
143146
147+ /** @type {CustomEventHandler } */
144148 const onLoad = ( sideEffects , logger ) => {
145149 sideEffects . add ( 'started polling current timestamp' , ( ) => {
146150 const handler = ( timestamp ) => {
@@ -155,6 +159,7 @@ export function setupDuckPlayerForYouTube(selectors, playbackPaused, environment
155159 }
156160 } ;
157161
162+ /** @type {CustomEventHandler } */
158163 const onInit = ( sideEffects , logger ) => {
159164 sideEffects . add ( 'subscribe to media control' , ( ) => {
160165 return messages . subscribeToMediaControl ( ( { pause } ) => {
@@ -188,6 +193,7 @@ export function setupDuckPlayerForYouTube(selectors, playbackPaused, environment
188193 * @param {DuckPlayerNativeMessages } messages
189194 */
190195export function setupDuckPlayerForNoCookie ( selectors , environment , messages ) {
196+ /** @type {CustomEventHandler } */
191197 const onLoad = ( sideEffects , logger ) => {
192198 sideEffects . add ( 'started polling current timestamp' , ( ) => {
193199 const handler = ( timestamp ) => {
0 commit comments