fix(comment/utterances): the target origin mismatch recipient window's origin (#735)

This commit is contained in:
Parasomnia 2022-12-06 23:55:40 +10:00 committed by GitHub
parent 3ff06fe033
commit d382ca993d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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>