Skip to content

Commit

Permalink
allow to override prefers-color-scheme via url param for guests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonathanmmm authored Nov 27, 2021
1 parent 686b2e1 commit cb5725d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions apps/accessibility/src/accessibilityoca.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@
import { loadState } from '@nextcloud/initial-state'

OCA.Accessibility = loadState('accessibility', 'data')
if (OCA.Accessibility.checkMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
// Overwrite the theme for Guests based on the prefers-color-scheme
// Force a specific theme for guests based on force-color-scheme param
var srv_url = new URL(window.location.href)
var force_color_scheme = srv_url.searchParams.get("force-color-scheme")
if(force_color_scheme !== null) {
if(force_color_scheme=="dark") {
OCA.Accessibility.theme = 'dark'
}
else {
OCA.Accessibility.theme = 'light'
}
}
else if (OCA.Accessibility.checkMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
// Overwrite the theme for guests based on the prefers-color-scheme
OCA.Accessibility.theme = 'dark'
}

Expand Down

0 comments on commit cb5725d

Please sign in to comment.