mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2024-11-27 04:03:48 +01:00
fix(comment/utterances): the target origin mismatch recipient window's origin (#735)
This commit is contained in:
parent
3ff06fe033
commit
d382ca993d
1 changed files with 6 additions and 0 deletions
|
@ -16,6 +16,8 @@
|
|||
</style>
|
||||
|
||||
<script>
|
||||
let utterancesLoaded = false;
|
||||
|
||||
function setUtterancesTheme(theme) {
|
||||
let utterances = document.querySelector('.utterances iframe');
|
||||
if (utterances) {
|
||||
|
@ -31,10 +33,14 @@
|
|||
|
||||
addEventListener('message', event => {
|
||||
if (event.origin !== 'https://utteranc.es') return;
|
||||
|
||||
/// Called when Utterances is ready
|
||||
utterancesLoaded = true;
|
||||
setUtterancesTheme(document.documentElement.dataset.scheme)
|
||||
});
|
||||
|
||||
window.addEventListener('onColorSchemeChange', (e) => {
|
||||
if (!utterancesLoaded) return;
|
||||
setUtterancesTheme(e.detail)
|
||||
})
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue