Skip to content

Commit

Permalink
Added system/browser scheme change detection to trigger update colors…
Browse files Browse the repository at this point in the history
  • Loading branch information
kudo-sync-bot committed Dec 22, 2024
1 parent e9c96ad commit 20036d7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions starters/chrome/extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@
settings.save('skipAlert', !config.skipAlert) }
)

// Monitor SCHEME CHANGES to update modal colors + env.scheme for your use
new MutationObserver(() => { env.scheme = getScheme() ; modals.stylize() })
.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] })
// Monitor SCHEME PREF CHANGES to update modal colors + env.scheme for your use
new MutationObserver(handleSchemePrefChange).observe( // for site scheme pref changes
document.documentElement, { attributes: true, attributeFilter: ['class'] })
window.matchMedia('(prefers-color-scheme: dark)').addEventListener( // for browser/system scheme pref changes
'change', () => requestAnimationFrame(handleSchemePrefChange))
function handleSchemePrefChange() {
const displayedScheme = getScheme()
if (env.scheme != displayedScheme) { env.scheme = displayedScheme ; modals.stylize() }
}

// Your code here...
// Your code here...
Expand Down

0 comments on commit 20036d7

Please sign in to comment.