Replies: 4 comments
|
I don't know the details of how your project handles theme switching, so I can only briefly explain how to update the theme on the giscus side. function setGiscusTheme(theme) {
const iframe = document.querySelector("iframe.giscus-frame");
if (!iframe) return;
iframe.contentWindow.postMessage(
{
giscus: {
setConfig: {
theme,
},
},
},
"https://giscus.app",
);
}Then call it whenever your site switches between light and dark mode: Related docs:
|
|
Yes. Giscus supports changing themes dynamically using function setGiscusTheme(theme) {
const iframe = document.querySelector('iframe.giscus-frame');
if (!iframe) return;
iframe.contentWindow.postMessage(
{
giscus: {
setConfig: {
theme: theme === 'dark' ? 'dark' : 'light'
}
}
},
'https://giscus.app'
);
}Call |
This comment was marked as low quality.
This comment was marked as low quality.
|
You can also listen for your website theme changes using MutationObserver and update giscus automatically. Example: const observer = new MutationObserver(() => { observer.observe(document.documentElement, { This will automatically sync giscus whenever your website theme changes. |
Uh oh!
There was an error while loading. Please reload this page.
I'm using giscus on my blog and want it to automatically switch between light/dark themes when my website changes mode.
Is there a way to do this with JavaScript?
All reactions