Skip to content

Commit

Permalink
read prefers-color-scheme only in main page
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Aug 30, 2023
1 parent a0de15b commit eef3a4d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions content/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@

// FIXME: move this to background page when following bugs are fixed:
// https://bugzil.la/1587723, https://crbug.com/968651
const mqDark = matchMedia('(prefers-color-scheme: dark)');
mqDark.onchange = e => API.colorScheme.updateSystemPreferDark(e.matches);
const mqDark = !isFrame && matchMedia('(prefers-color-scheme: dark)');
if (mqDark) mqDark.onchange = e => API.colorScheme.updateSystemPreferDark(e.matches);

// Declare all vars before init() or it'll throw due to "temporal dead zone" of const/let
init();
Expand Down Expand Up @@ -268,7 +268,7 @@
// In Chrome content script is orphaned on an extension update/reload
// so we need to detach event listeners
window.removeEventListener(orphanEventId, orphanCheck, true);
mqDark.onchange = null;
if (mqDark) mqDark.onchange = null;
isOrphaned = true;
setTimeout(styleInjector.clear, 1000); // avoiding FOUC
tryCatch(msg.off, applyOnMessage);
Expand Down

0 comments on commit eef3a4d

Please sign in to comment.