Skip to content

Commit 06cd8e2

Browse files
committed
allow to override prefers-color-scheme via url param for guests
using ?force-color-scheme=light should make the theme light and ?force-color-scheme=dark should make it dark. Useful for iframes to match a website theme and to send a specific theme to a guest. Signed-off-by: jonathanmmm <32403139+jonathanmmm@users.noreply.github.com>
1 parent 686b2e1 commit 06cd8e2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

apps/accessibility/src/accessibilityoca.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,19 @@
2424
import { loadState } from '@nextcloud/initial-state'
2525

2626
OCA.Accessibility = loadState('accessibility', 'data')
27-
if (OCA.Accessibility.checkMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
28-
// Overwrite the theme for Guests based on the prefers-color-scheme
27+
// Force a specific theme for guests based on force-color-scheme param
28+
var srv_url = new URL(window.location.href)
29+
var force_color_scheme = srv_url.searchParams.get("force-color-scheme")
30+
if(force_color_scheme !== null) {
31+
if(force_color_scheme=="dark") {
32+
OCA.Accessibility.theme = 'dark'
33+
}
34+
else {
35+
OCA.Accessibility.theme = 'light'
36+
}
37+
}
38+
else if (OCA.Accessibility.checkMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
39+
// Overwrite the theme for guests based on the prefers-color-scheme
2940
OCA.Accessibility.theme = 'dark'
3041
}
3142

0 commit comments

Comments
 (0)