diff --git a/assets/js/theme.js b/assets/js/theme.js index 718a73e9..78f485b2 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -955,13 +955,24 @@ class FixIt { document.querySelector('.giscus-frame')?.contentWindow.postMessage({ giscus: message }, giscusConfig.origin); }); this.switchThemeEventSet.add(this._giscusOnSwitchTheme); - this.giscus2parentMsg = window.addEventListener('message', (event) => { + // gicuss to parent message + this._messageListener = (event) => { + if (event.origin !== giscusConfig.origin) return; const $script = document.querySelector('#giscus>script'); if ($script){ - this._giscusOnSwitchTheme(); $script.parentElement.removeChild($script); } - }, { once: true }); + const frame = document.querySelector('.giscus-frame'); + if (frame.getAttribute('loading') === 'lazy') { + frame.addEventListener('load', (e) => { + this._giscusOnSwitchTheme(); + }, { once: true }); + } else { + this._giscusOnSwitchTheme(); + } + window.removeEventListener('message', this._messageListener, false); + }; + window.addEventListener('message', this._messageListener, false); return; } } diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index ebbdbacd..257c1e32 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.17-03b3bfbd" -}} +{{- .Scratch.Set "version" "v0.3.17-c0b9a51d" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}}