@@ -18,15 +18,53 @@ const ThemeToggleButton = () => {
1818
1919  const  getCookieOptions  =  ( serverURL )  =>  ( {  domain : serverURL . hostname ,  path : '/' ,  expires : getCookieExpiry ( )  } ) ; 
2020
21+   const  addDarkThemeToIframes  =  ( )  =>  { 
22+     const  iframes  =  document . getElementsByTagName ( 'iframe' ) ; 
23+     const  iframesLength  =  iframes . length ; 
24+     if  ( iframesLength  >  0 )  { 
25+       Array . from ( {  length : iframesLength  } ) . forEach ( ( _ ,  ind )  =>  { 
26+         const  style  =  document . createElement ( 'style' ) ; 
27+         style . textContent  =  ` 
28+           body{ 
29+             background-color: #0D0D0E; 
30+             color: #ccc; 
31+           } 
32+           a {color: #ccc;} 
33+           a:hover{color: #d3d3d3;} 
34+           ` ; 
35+         if  ( iframes [ ind ] . contentDocument )  {  iframes [ ind ] . contentDocument . head . appendChild ( style ) ;  } 
36+       } ) ; 
37+     } 
38+   } ; 
39+ 
40+   const  removeDarkThemeFromiframes  =  ( )  =>  { 
41+     const  iframes  =  document . getElementsByTagName ( 'iframe' ) ; 
42+     const  iframesLength  =  iframes . length ; 
43+ 
44+     Array . from ( {  length : iframesLength  } ) . forEach ( ( _ ,  ind )  =>  { 
45+       if  ( iframes [ ind ] . contentDocument )  { 
46+         const  iframeHead  =  iframes [ ind ] . contentDocument . head ; 
47+         const  styleTag  =  Array . from ( iframeHead . querySelectorAll ( 'style' ) ) . find ( 
48+           ( style )  =>  style . textContent . includes ( 'background-color: #0D0D0E;' )  &&  style . textContent . includes ( 'color: #ccc;' ) , 
49+         ) ; 
50+         if  ( styleTag )  { 
51+           styleTag . remove ( ) ; 
52+         } 
53+       } 
54+     } ) ; 
55+   } ; 
56+ 
2157  const  onToggleTheme  =  ( )  =>  { 
2258    const  serverURL  =  new  URL ( getConfig ( ) . LMS_BASE_URL ) ; 
2359    let  theme  =  '' ; 
2460
2561    if  ( cookies . get ( themeCookie )  ===  'dark' )  { 
2662      document . body . classList . remove ( 'indigo-dark-theme' ) ; 
63+       removeDarkThemeFromiframes ( ) ; 
2764      theme  =  'light' ; 
2865    }  else  { 
2966      document . body . classList . add ( 'indigo-dark-theme' ) ; 
67+       addDarkThemeToIframes ( ) ; 
3068      theme  =  'dark' ; 
3169    } 
3270    cookies . set ( themeCookie ,  theme ,  getCookieOptions ( serverURL ) ) ; 
0 commit comments