hugo-theme-stack/layouts/partials/comments/provider/utterances.html
k e90adc4773 change document.body.dataset.scheme to document.documentElement.dataset.scheme
When the dark mode is on or when the light mode is on, the
[data-scheme="light"] or [data-scheme="dark"], respectively, will be
placed in the <html> tag. Allowing us to access the dark and light color
schemes from the <html> to change the vertical scrollbar styles
according to the current color scheme.
2021-06-14 17:04:06 -05:00

41 lines
1.1 KiB
HTML

<script src="https://utteranc.es/client.js"
repo="{{ .Site.Params.comments.utterances.repo }}"
issue-term="{{ .Site.Params.comments.utterances.issueTerm }}"
{{ with .Site.Params.comments.utterances.label }}
label="{{ . }}"
{{ end }}
crossorigin="anonymous"
async
>
</script>
<style>
.utterances {
max-width: unset;
}
</style>
<script>
function setUtterancesTheme(theme) {
let utterances = document.querySelector('.utterances iframe');
if (utterances) {
utterances.contentWindow.postMessage(
{
type: 'set-theme',
theme: `github-${theme}`
},
'https://utteranc.es'
);
}
}
addEventListener('message', event => {
if (event.origin !== 'https://utteranc.es') return;
setUtterancesTheme(document.documentElement.dataset.scheme)
});
window.addEventListener('onColorSchemeChange', (e) => {
setUtterancesTheme(e.detail)
})
</script>