Merge pull request #546 from nunocoracao/519-ios-notch-on-safari-ignores-theme-colors

 add support for meta theme-color with bg color
This commit is contained in:
Nuno Coração 2023-02-25 19:17:41 +00:00 committed by GitHub
commit 566992e41b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -26,6 +26,8 @@ window.addEventListener("DOMContentLoaded", (event) => {
const switcher = document.getElementById("appearance-switcher");
const switcherMobile = document.getElementById("appearance-switcher-mobile");
updateMeta()
if (switcher) {
switcher.addEventListener("click", () => {
document.documentElement.classList.toggle("dark");
@ -33,6 +35,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
"appearance",
document.documentElement.classList.contains("dark") ? "dark" : "light"
);
updateMeta()
});
switcher.addEventListener("contextmenu", (event) => {
event.preventDefault();
@ -46,10 +49,22 @@ window.addEventListener("DOMContentLoaded", (event) => {
"appearance",
document.documentElement.classList.contains("dark") ? "dark" : "light"
);
updateMeta()
});
switcherMobile.addEventListener("contextmenu", (event) => {
event.preventDefault();
localStorage.removeItem("appearance");
});
}
});
});
var updateMeta = () => {
var elem, style;
elem = document.querySelector('body');
console.log(elem)
style = getComputedStyle(elem);
console.log(style.backgroundColor)
document.querySelector('meta[name="theme-color"]').setAttribute('content', style.backgroundColor);
}

View file

@ -118,7 +118,7 @@
{{ if templates.Exists "partials/extend-head.html" }}
{{ partialCached "extend-head.html" .Site }}
{{ end }}
<meta name="theme-color"/>
{{/* Firebase */}}
{{ with $.Site.Params.firebase }}
{{ if isset $.Site.Params "firebase" }}