11const VIDEO_ASPECT_RATIO = 56.25 ; // 16:9 aspect ratio
22
3- function createStyledElement ( tagName , styles = { } ) {
3+ function createStyledElement ( tagName : string , styles : { } ) {
44 const element = document . createElement ( tagName ) ;
5- for ( let [ key , value ] of Object . entries ( styles ) ) {
6- element . style [ key ] = value ;
5+ for ( const [ key , value ] of Object . entries ( styles ) ) {
6+ if ( typeof element . style [ key as any ] !== 'undefined' ) {
7+ ( element . style as any ) [ key ] = value ;
8+ }
79 }
810 return element ;
911}
1012
11- function createButton ( content , className , styles = { } ) {
13+ function createButton ( content : string , className : string , styles = { } ) {
1214 const button = createStyledElement ( 'button' , styles ) ;
1315 button . textContent = content ;
1416 button . classList . add ( className ) ;
1517 return button ;
1618}
1719
18- function createControlsContainer ( channelName ) {
20+ function createControlsContainer ( channelName : string ) {
1921 const controlsContainer = createStyledElement ( 'div' , {
2022 display : 'flex' ,
2123 justifyContent : 'center' ,
@@ -35,7 +37,7 @@ function createControlsContainer(channelName) {
3537 } ) ;
3638 channelElement . classList . add ( 'channel' ) ; // add this line
3739 channelElement . textContent = channelName ;
38- channelElement . fontWeight = 'bold ' ;
40+ channelElement . style . fontWeight = '600 ' ;
3941 channelElement . style . color = 'lightcyan' ;
4042 channelElement . style . textShadow = '0 0 5px #000000' ;
4143 channelElement . style . fontFamily = 'Menlo, Monaco, Consolas, "Courier New", monospace'
@@ -53,7 +55,7 @@ function createControlsContainer(channelName) {
5355 return { controlsContainer, prevButton, nextButton, toggleButton } ;
5456}
5557
56- function createVideoContainer ( videoUrl , channelName ) {
58+ function createVideoContainer ( videoUrl : string , channelName : string ) {
5759 const container = createStyledElement ( 'div' , {
5860 position : 'relative' ,
5961 display : 'flex' ,
@@ -74,7 +76,7 @@ function createVideoContainer(videoUrl, channelName) {
7476 width : '95%' ,
7577 height : '95%' ,
7678 border : '1px solid grey'
77- } ) ;
79+ } ) as HTMLIFrameElement ;
7880 iframe . classList . add ( 'youtube-video' ) ;
7981 iframe . src = videoUrl ;
8082 iframe . allowFullscreen = true ;
@@ -97,7 +99,7 @@ function addVideo(title: string) {
9799 if ( existingContainer ) return ;
98100
99101 chrome . storage . local . get ( [ 'leetcodeProblems' ] , ( result ) => {
100- const problem = result . leetcodeProblems . questions . find ( ( problem ) => problem . title === title ) ;
102+ const problem = result . leetcodeProblems . questions . find ( ( problem : { title : string } ) => problem . title === title ) ;
101103 if ( problem ?. videos ?. length ) {
102104 let currentVideoIndex = 0 ;
103105 const { container, iframe, prevButton, nextButton, toggleButton } = createVideoContainer (
@@ -109,7 +111,7 @@ function addVideo(title: string) {
109111 prevButton ?. addEventListener ( 'click' , ( ) => {
110112 currentVideoIndex = ( currentVideoIndex - 1 + problem . videos . length ) % problem . videos . length ;
111113 updateVideo (
112- container ,
114+ container as HTMLDivElement ,
113115 problem . videos [ currentVideoIndex ] . embedded_url ,
114116 problem . videos [ currentVideoIndex ] . channel ,
115117 ) ;
@@ -118,14 +120,14 @@ function addVideo(title: string) {
118120 nextButton ?. addEventListener ( 'click' , ( ) => {
119121 currentVideoIndex = ( currentVideoIndex + 1 ) % problem . videos . length ;
120122 updateVideo (
121- container ,
123+ container as HTMLDivElement ,
122124 problem . videos [ currentVideoIndex ] . embedded_url ,
123125 problem . videos [ currentVideoIndex ] . channel ,
124126 ) ;
125127 } ) ;
126128
127129 toggleButton ?. addEventListener ( 'click' , ( ) => {
128- const videoContainer = document . querySelector ( 'div.video-container' ) ;
130+ const videoContainer = document . querySelector ( 'div.video-container' ) as HTMLDivElement ;
129131 if ( videoContainer ) {
130132 videoContainer . style . paddingBottom = videoContainer . style . paddingBottom === '0%' ? `${ VIDEO_ASPECT_RATIO } % ` : '0%' ;
131133 if ( videoContainer . style . paddingBottom === '0%' ) {
@@ -151,8 +153,8 @@ function addVideo(title: string) {
151153 } ) ;
152154}
153155
154- function updateVideo ( container , videoUrl , channelName ) {
155- const iframe = container . querySelector ( 'iframe.youtube-video' ) ;
156+ function updateVideo ( container : HTMLDivElement , videoUrl : string , channelName : string ) {
157+ const iframe = container . querySelector ( 'iframe.youtube-video' ) as HTMLIFrameElement ;
156158 const channelElement = container . querySelector ( 'div.channel' ) ;
157159
158160 if ( iframe ) iframe . src = videoUrl ;
@@ -172,14 +174,14 @@ chrome.runtime.onMessage.addListener((request) => {
172174 * Prevents the iframe from freezing when it's being resized while the mouse is hovering over it.
173175 */
174176window . addEventListener ( 'mousedown' , ( ) => {
175- const iframe = document . querySelector ( 'iframe.youtube-video' ) ;
177+ const iframe = document . querySelector ( 'iframe.youtube-video' ) as HTMLIFrameElement ;
176178 if ( iframe ) {
177179 iframe . style . pointerEvents = 'none' ;
178180 }
179181} ) ;
180182
181183window . addEventListener ( 'mouseup' , ( ) => {
182- const iframe = document . querySelector ( 'iframe.youtube-video' ) ;
184+ const iframe = document . querySelector ( 'iframe.youtube-video' ) as HTMLIFrameElement ;
183185 if ( iframe ) {
184186 iframe . style . pointerEvents = 'auto' ;
185187 }
0 commit comments