@@ -28,7 +28,6 @@ let device = {
2828
2929
3030
31-
3231// FOR TESTING ONLY
3332/*let LANGUAGE = {
3433 "//":"German language translations",
@@ -320,8 +319,12 @@ function iframeSetup(options) {
320319 // Style custom apps for dark mode
321320 const iframeDoc = iframe . contentDocument || iframe . contentWindow . document ;
322321 if ( iframeDoc && iframeDoc . body ) {
323- const bgColor = window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? '#2c2c2c' : '#ffffff' ;
324- const textColor = window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? '#FFFFFF' : '#000000' ;
322+ var theme = SETTINGS . theme ;
323+ var prefersDark ;
324+ if ( theme == "device" ) prefersDark = window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ;
325+ else prefersDark = ( theme == "dark" ) ;
326+ var bgColor = prefersDark ? '#2c2c2c' : '#ffffff' ;
327+ var textColor = prefersDark ? '#FFFFFF' : '#000000' ;
325328 iframeDoc . body . style . backgroundColor = bgColor ;
326329 iframeDoc . body . style . color = textColor ;
327330 }
@@ -445,7 +448,7 @@ function handleCustomApp(appTemplate) {
445448 </div>
446449 <div class="modal-body" style="height:100%">
447450 <div class="content" style="height:100%">
448- <iframe class="modal-iframe" src="apps/${ appTemplate . id } /${ appTemplate . custom } " style="width:100%;height:100%;border:0px;">
451+ <iframe src="apps/${ appTemplate . id } /${ appTemplate . custom } " style="width:100%;height:100%;border:0px;">
449452 </div>
450453 </div>
451454 </div>
@@ -1414,7 +1417,7 @@ function loadSettings() {
14141417 }
14151418 // upgrade old settings
14161419 if ( ! SETTINGS . appsfavouritedThisSession ) SETTINGS . appsfavouritedThisSession = DEFAULTSETTINGS . appsfavouritedThisSession ;
1417- if ( ! SETTINGS . theme ) SETTINGS . theme = SETTINGS . theme = DEFAULTSETTINGS . theme ;
1420+ if ( ! SETTINGS . theme ) SETTINGS . theme = DEFAULTSETTINGS . theme ;
14181421}
14191422/// Save settings
14201423function saveSettings ( ) {
@@ -1435,25 +1438,20 @@ function settingsCheckbox(id, name) {
14351438 saveSettings ( ) ;
14361439 } ) ;
14371440}
1438- function applyTheme ( theme ) {
1441+ function changeThemeVars ( theme ) {
1442+ document . documentElement . style . colorScheme = theme ;
1443+ document . documentElement . setAttribute ( 'data-theme' , theme ) ;
14391444
1440- if ( theme == "dark" ) document . documentElement . style . colorScheme = 'dark' ;
1441- else if ( theme == "light" ) document . documentElement . style . colorScheme = 'light' ;
1445+ }
1446+ function applyTheme ( theme ) {
1447+ if ( theme == "light" || theme == "dark" ) changeThemeVars ( theme ) ;
14421448 else {
1443-
14441449 const prefersDark = window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ;
1445- console . log ( prefersDark )
1446- const theme = prefersDark ? 'dark' : 'light' ;
1447- document . documentElement . style . colorScheme = theme ;
1450+ const computedTheme = prefersDark ? 'dark' : 'light' ;
1451+ changeThemeVars ( computedTheme ) ;
14481452 }
14491453}
1450- function repaintSite ( ) {
1451- //tricks browser into repainting the site to apply theme changes
1452- const body = document . body ;
1453- body . style . display = 'none' ;
1454- body . offsetHeight ;
1455- body . style . display = '' ;
1456- }
1454+
14571455settingsCheckbox ( "settings-pretokenise" , "pretokenise" ) ;
14581456settingsCheckbox ( "settings-minify" , "minify" ) ;
14591457settingsCheckbox ( "settings-settime" , "settime" ) ;
@@ -1462,7 +1460,7 @@ settingsCheckbox("settings-autoReload", "autoReload");
14621460settingsCheckbox ( "settings-nopacket" , "noPackets" ) ;
14631461loadSettings ( ) ;
14641462
1465- selectTheme = document . getElementById ( "settings-theme" ) ;
1463+ const selectTheme = document . getElementById ( "settings-theme" ) ;
14661464// Update theme selector
14671465selectTheme . value = SETTINGS . theme ;
14681466selectTheme . addEventListener ( "change" , event => {
@@ -1477,7 +1475,7 @@ applyTheme(SETTINGS.theme);
14771475window . matchMedia ( '(prefers-color-scheme: dark)' ) . addEventListener ( 'change' , ( e ) => {
14781476 if ( SETTINGS . theme == "device" ) {
14791477 const newTheme = e . matches ? 'dark' : 'light' ;
1480- document . documentElement . style . colorScheme = newTheme ;
1478+ changeThemeVars ( newTheme ) ;
14811479 }
14821480} ) ;
14831481
0 commit comments