1
Fork 0

take into account the system theme

This commit is contained in:
Guillaume Gomez 2019-05-27 15:57:44 +02:00
parent 7858dc237d
commit c076d30ce4
2 changed files with 28 additions and 3 deletions

View file

@ -86,7 +86,7 @@ function getCurrentValue(name) {
return null;
}
function switchTheme(styleElem, mainStyleElem, newTheme) {
function switchTheme(styleElem, mainStyleElem, newTheme, skipStorage) {
var fullBasicCss = "rustdoc" + resourcesSuffix + ".css";
var fullNewTheme = newTheme + resourcesSuffix + ".css";
var newHref = mainStyleElem.href.replace(fullBasicCss, fullNewTheme);
@ -109,8 +109,18 @@ function switchTheme(styleElem, mainStyleElem, newTheme) {
});
if (found === true) {
styleElem.href = newHref;
updateLocalStorage("rustdoc-theme", newTheme);
// If this new value comes from a system setting or from the previously saved theme, no
// need to save it.
if (skipStorage !== true) {
updateLocalStorage("rustdoc-theme", newTheme);
}
}
}
switchTheme(currentTheme, mainTheme, getCurrentValue("rustdoc-theme") || "light");
function getSystemValue() {
return getComputedStyle(document.documentElement).getPropertyValue('content');
}
switchTheme(currentTheme, mainTheme,
getCurrentValue("rustdoc-theme") || getSystemValue() || "light",
true);