Last active
December 23, 2018 21:44
-
-
Save zentrope/7b4ea586256804cceb585ce19f781c20 to your computer and use it in GitHub Desktop.
Set dark/light for web content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func setMode(_ isDark: Bool) { | |
let mode = isDark ? "add" : "remove" | |
let script = "document.body.classList.\(mode)(\"dark\");" | |
webView.evaluateJavaScript(script) { result, error in | |
if let err = error { | |
os_log("%{public}s", log: logger, type: .error, "js error: \(err).") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment