fix: avoid `utterances` initialization failure (#1234)

This issue exists since Chirpy `v6.0.0`
This commit is contained in:
Cotes Chung 2023-09-15 01:24:13 +08:00 committed by GitHub
parent bb589e8d31
commit b34661efd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -8,16 +8,17 @@
></script>
<script type="text/javascript">
$(function () {
(function () {
const origin = 'https://utteranc.es';
const iframe = 'iframe.utterances-frame';
const lightTheme = 'github-light';
const darkTheme = 'github-dark';
let initTheme = lightTheme;
const html = document.documentElement;
if (
$('html[data-mode=dark]').length > 0 ||
($('html[data-mode]').length == 0 && window.matchMedia('(prefers-color-scheme: dark)').matches)
(html.hasAttribute('data-mode') && html.getAttribute('data-mode') === 'dark') ||
(!html.hasAttribute('data-mode') && window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
initTheme = darkTheme;
}
@ -45,5 +46,5 @@
const utterances = document.querySelector(iframe).contentWindow;
utterances.postMessage(message, origin);
});
});
})();
</script>