Darkmode.js
Darkmode.js copied to clipboard
Allow running callbacks when `button` is clicked
Thanks for maintaining darkmode.js.
This is a feature request. It would be nice to run some additional custom javascript code on light / dark mode toggle. For example, a user might want to toggle the theme of their comments using this:
const iframe = document.querySelector("iframe.giscus-frame");
iframe.contentWindow.postMessage({giscus: {setConfig: {theme: "dark"}}}, "https://giscus.app/");
It would be great if the constructor accepted a callback that was called in the on click handler for the button for toggling the light / dark mode.
Hey that's a nice idea, if you have some time feel free to implement it! I'll happily review, merge and deploy the feature.
This works:
var darkmode = new Darkmode();
darkmode.button.addEventListener('click', () => {
console.log("hello cb");
});