Skip to content

Commit

Permalink
fix: init giscus message event
Browse files Browse the repository at this point in the history
  • Loading branch information
isunjn committed Dec 25, 2023
1 parent daddf73 commit 8ad1158
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function enableThemeToggle() {
const iframe = document.querySelector('iframe.giscus-frame');
if (iframe) iframe.contentWindow.postMessage({ giscus: { setConfig: { theme: `${location.origin}/giscus_${theme}.css` } } }, 'https://giscus.app');
}
function initGiscusTheme() {
function initGiscusTheme(evt) {
if (evt.origin !== 'https://giscus.app') return;
if (!(typeof evt.data === 'object' && evt.data.giscus)) return;
toggleGiscusTheme(sessionStorage.getItem("theme") || (preferDark.matches ? "dark" : "light"));
window.removeEventListener('message', initGiscusTheme);
}
Expand Down

0 comments on commit 8ad1158

Please sign in to comment.