Skip to content

Instantly share code, notes, and snippets.

@makoru-hikage
Last active September 30, 2021 09:50
Show Gist options
  • Save makoru-hikage/cf493c164c3e9e7db6401c0aecebf8b6 to your computer and use it in GitHub Desktop.
Save makoru-hikage/cf493c164c3e9e7db6401c0aecebf8b6 to your computer and use it in GitHub Desktop.
A Rescript code used to check if a browser is in Dark Mode
// https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList
type mediaQueryList = {
matches: bool,
domString: string
}
// https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
@val @scope("window")
external matchMedia: string => mediaQueryList = "matchMedia"
// Check if the browser is in Dark Mode using the MediaQuery
let isInDarkMode = matchMedia("(prefers-color-scheme: dark)").matches
@makoru-hikage
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment