Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support night mode when using share by URL
- Loading branch information
Andrew Dolgov
committed
Jan 19, 2020
1 parent
303f8fb
commit aa56bca
Showing
10 changed files
with
388 additions
and
202 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Event.observe(window, "load", function() { | ||
const UtilityJS = { | ||
apply_night_mode: function (is_night, link) { | ||
console.log("night mode changed to", is_night); | ||
|
||
if (link) { | ||
const css_override = is_night ? "themes/night.css" : "css/default.css"; | ||
|
||
link.setAttribute("href", css_override + "?" + Date.now()); | ||
} | ||
}, | ||
setup_night_mode: function() { | ||
const mql = window.matchMedia('(prefers-color-scheme: dark)'); | ||
|
||
const link = new Element("link", { | ||
rel: "stylesheet", | ||
id: "theme_auto_css" | ||
}); | ||
|
||
link.onload = function() { | ||
document.querySelector("body").removeClassName("css_loading"); | ||
}; | ||
|
||
try { | ||
mql.addEventListener("change", () => { | ||
UtilityJS.apply_night_mode(mql.matches, link); | ||
}); | ||
} catch (e) { | ||
console.warn("exception while trying to set MQL event listener"); | ||
} | ||
|
||
document.querySelector("head").appendChild(link); | ||
|
||
UtilityJS.apply_night_mode(mql.matches, link); | ||
} | ||
}; | ||
|
||
UtilityJS.setup_night_mode(); | ||
}); |
Oops, something went wrong.