diff --git a/src/pyj/book_list/book_details.pyj b/src/pyj/book_list/book_details.pyj index c8507d7fab..947f628e68 100644 --- a/src/pyj/book_list/book_details.pyj +++ b/src/pyj/book_list/book_details.pyj @@ -16,7 +16,7 @@ from book_list.library_data import ( ) from book_list.router import back, home, open_book, report_a_load_failure from book_list.theme import ( - browser_in_dark_mode, get_color, get_color_as_rgba, get_font_size + color_scheme, get_color, get_color_as_rgba, get_font_size ) from book_list.top_bar import add_button, clear_buttons, create_top_bar, set_title from book_list.ui import query_as_href, set_panel_handler, show_panel @@ -155,8 +155,7 @@ if window?: def adjusting_sandboxed_html(html, extra_css): color = get_color_as_rgba('window-foreground') - cs = 'dark' if browser_in_dark_mode() else 'light' - css = f'\n\n:root {{ color-scheme: {cs} }}\n\nhtml, body {{ overflow: hidden; color: rgba({color[0]}, {color[1]}, {color[2]}, {color[3]}) }}' + css = f'\n\n:root {{ color-scheme: {color_scheme()} }}\n\nhtml, body {{ overflow: hidden; color: rgba({color[0]}, {color[1]}, {color[2]}, {color[3]}) }}' if extra_css: css += '\n\n' + extra_css # allow-same-origin is needed for resizing and allow-popups is needed for diff --git a/src/pyj/book_list/comments_editor.pyj b/src/pyj/book_list/comments_editor.pyj index 8fab1af25b..a9f63cdd6a 100644 --- a/src/pyj/book_list/comments_editor.pyj +++ b/src/pyj/book_list/comments_editor.pyj @@ -4,7 +4,7 @@ from __python__ import bound_methods, hash_literals from elementmaker import E -from book_list.theme import browser_in_dark_mode, get_color, get_color_as_rgba +from book_list.theme import color_scheme, get_color, get_color_as_rgba from dom import add_extra_css, build_rule, clear, svgicon from gettext import gettext as _ from iframe_comm import IframeClient, create_wrapped_iframe @@ -396,8 +396,7 @@ class Editor: self.pending_set_html = html return rgba = get_color_as_rgba('window-foreground') - cs = 'dark' if browser_in_dark_mode() else 'light' - self.iframe_wrapper.send_message('set_html', html=html, color_scheme=cs, color=f'rgba({rgba[0]},{rgba[1]},{rgba[2]},{rgba[3]})') + self.iframe_wrapper.send_message('set_html', html=html, color_scheme=color_scheme(), color=f'rgba({rgba[0]},{rgba[1]},{rgba[2]},{rgba[3]})') def get_html(self, proceed): self.get_html_callbacks.push(proceed) diff --git a/src/pyj/book_list/theme.pyj b/src/pyj/book_list/theme.pyj index 622b9f4422..648cea02e1 100644 --- a/src/pyj/book_list/theme.pyj +++ b/src/pyj/book_list/theme.pyj @@ -81,6 +81,10 @@ def browser_in_dark_mode(): return window.matchMedia('(prefers-color-scheme: dark)').matches +def color_scheme(): + return 'dark' if browser_in_dark_mode() or document.documentElement.style.colorScheme is 'dark' else 'light' + + def css_for_variables(): input_css = ''' input, textarea {