fix: avoid utterances
initialization failure (#1234)
This issue exists since Chirpy `v6.0.0`
This commit is contained in:
parent
bb589e8d31
commit
b34661efd7
1 changed files with 5 additions and 4 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue