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