Darkmode.js icon indicating copy to clipboard operation
Darkmode.js copied to clipboard

Allow running callbacks when `button` is clicked

Open kdheepak opened this issue 2 years ago • 2 comments

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.

kdheepak avatar May 13 '22 12:05 kdheepak

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.

sandoche avatar May 29 '22 09:05 sandoche

This works:

var darkmode = new Darkmode();
darkmode.button.addEventListener('click', () => {
        console.log("hello cb");
});

eugenekolo avatar May 02 '23 17:05 eugenekolo