How to make a listener for theme changing?
I need this to switch the theme of the comments correspondingly.
“css-change”
1 Like
But I don’t think that I have the app.workspace
.
How to subscribe with Obsidian Publish API?
Would a Mutation Observer
satisfy your need? You can listen to the body
element and tracking changes between theme-dark
and theme-light
class.
Code example here https://github.com/Acylation/obsidian-chem/blob/main/src/themeObserver.ts
Update on lifecycle management
// called by plugin `onload()`
themeObserver.observe(document.body, {
attributes: true,
attributeOldValue: true,
attributeFilter: ['class'],
});
// called by plugin `onunload()`
themeObserver.disconnect();
1 Like
Sure I could do this.
It’s just that I hoped to find an API way: since it’s available now, I think it’s up to the API to provide such an integration.
1 Like
Ok, since there seem to be no other way, I’ll use DOM Mutation Observer. Thanks!