Skip to content

Commit

Permalink
perf(UI): use css filter to adapt dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed Sep 20, 2023
1 parent 2bff97f commit 06e376e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ - (NSString *)getAllIframeHTMLResultOfWord:(NSString *)word languages:(NSArray<E

// Update background color for dark mode
NSString *dictBackgroundColorCSS = [NSString stringWithFormat:@"<style>"
@"body { background-color: %@; }"
@"body { background-color: %@; color: %@}"

@"@media (prefers-color-scheme: dark) {"
@"body { background-color: %@; }"
@"body { background-color: %@; filter: invert(0.85) hue-rotate(185deg) saturate(200%%) brightness(120%%);}"
@"}"
@"</style>",

lightBackgroundColorString, darkBackgroundColorString];
lightBackgroundColorString, lightTextColorString, darkBackgroundColorString];

NSString *dictHTML = [NSString stringWithFormat:@"%@ \n\n%@ \n\n%@", customCSS, dictBackgroundColorCSS, wordHtmlString];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
}

@media (prefers-color-scheme: dark) {

details summary::before,
details summary::after {
background: var(--dark-text-color);
Expand Down Expand Up @@ -444,8 +443,8 @@
}

if (isDarkMode()) {
updateAllIframeColor(true);
updateBackgroundColor(true);
// updateAllIframeColor(true);
// updateBackgroundColor(true);
}

updateAllIframeStyle();
Expand All @@ -465,8 +464,8 @@
);
colorSchemeListener.addEventListener(`change`, function (event) {
var isDarkMode = event.matches;
updateAllIframeColor(isDarkMode);
updateBackgroundColor(isDarkMode);
// updateAllIframeColor(isDarkMode);
// updateBackgroundColor(isDarkMode);
});
};
</script>
Expand Down

0 comments on commit 06e376e

Please sign in to comment.