Replies: 2 comments
-
If you want to access the user's theme from your SQL files, you can store it in a cookie from javascript, and reload the page: const currentTheme = document.cookie.split('; ').find(row => row.startsWith('theme='))?.split('=')[1];
const newTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
if (currentTheme !== newTheme) {
document.cookie = `theme=${newTheme}; path=/; max-age=31536000`; // Set cookie for 1 year
window.location.reload(); // Reload the page
} Then you can use the theme from sql: select 'shell' as component, sqlpage.cookie('theme') as theme; |
Beta Was this translation helpful? Give feedback.
0 replies
-
Many thanks! It works with Chromium on Gnome 47, YMMV. For the record, I did the following: Create a file called
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In CSS, the dark/light mode of the user's OS can be detected automatically (e.g. without the user having to click on a button to select 'dark' if she's running a dark theme in Gnome).
Example for a very basic website using the Solarized theme:
I would like to achieve this with SQLpage. I have tried to include a css file into
shell.sql
like this:The corresponding css file being:
The thing is: I don't know what to put as light/dark css directives. SQLpage already provides a dark theme, that can be set in
shell.sql
; I'd like it to be used when the user's OS is in dark mode automatically, otherwise use the light theme by default.For the moment, I use this technique, but the user has to click on the ' ☀ ' button if she's using dark mode, which is a (admittedly very minor) inconvenience.
I would be grateful for any suggestion. Many thanks!
Beta Was this translation helpful? Give feedback.
All reactions