Switch prism and comments theme on changes

This commit is contained in:
Dave Gallant
2024-01-07 17:17:46 -05:00
parent 29a621a4c3
commit c12f2173db
7 changed files with 40 additions and 166 deletions

View File

@@ -5,25 +5,22 @@
.Page.Site.Params.comments.utterances.github.repository -}}
<script>
// load utteranc comment
var getTheme = window.localStorage && window.localStorage.getItem("theme");
getTheme =
getTheme == null
? window.matchMedia &&
window.matchMedia("(prefers-color-scheme: light)").matches
? "light"
: "dark"
: getTheme;
// load comments
var getTheme =
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: light)").matches
? "light"
: "dark";
getTheme = getTheme == null ? "dark" : getTheme;
let theme = getTheme === "dark" ? "gruvbox-dark" : "github-light";
let s = document.createElement("script");
s.src = "https://utteranc.es/client.js";
s.setAttribute("repo", '{{ print $username "/" $repository }}');
s.setAttribute("issue-term", "{{ $issueTerm }}");
s.setAttribute("theme", theme);
s.setAttribute("crossorigin", "anonymous");
s.setAttribute("async", "");
let script = document.createElement("script");
script.src = "https://utteranc.es/client.js";
script.setAttribute("repo", '{{ print $username "/" $repository }}');
script.setAttribute("issue-term", "{{ $issueTerm }}");
script.setAttribute("theme", theme);
script.setAttribute("crossorigin", "anonymous");
script.setAttribute("async", "");
document.querySelector("div.comments").innerHTML = "";
document.querySelector("div.comments").appendChild(s);
document.querySelector("div.comments").appendChild(script);
</script>