UNPKG

@whop/react

Version:

React SDK for building embedded apps on Whop

19 lines (18 loc) 608 B
export function script() { const cookie = document.cookie.match(/whop-frosted-theme=appearance:(?<appearance>light|dark)/)?.groups; const el = document.documentElement; const classes = [ "light", "dark" ]; const theme = cookie ? cookie.appearance : getSystemTheme(); function updateDOM(theme) { el.classList.remove(...classes); el.classList.add(theme); el.style.colorScheme = theme; } function getSystemTheme() { return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; } updateDOM(theme); }