Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose background color to JS? #13

Open
ryanpcmcquen opened this issue Sep 13, 2020 · 7 comments
Open

Expose background color to JS? #13

ryanpcmcquen opened this issue Sep 13, 2020 · 7 comments

Comments

@ryanpcmcquen
Copy link
Contributor

I'd like to detect dark themes with my extension, and apply a CSS filter based on that, but I can't find a way to access the style kit background color inside of my extension, I've tried all the ComponentManager permissions I can find, but nothing seems to have the style sheet. I can access the the name of the style sheet under activeThemes, but I can't read the CSS rules because of iframe CORS limitations. Is there a way to just get the background color of the parent html passed down?

@ryanpcmcquen
Copy link
Contributor Author

More details here: ryanpcmcquen/standardnotes_org_mode_editor#5

@ryanpcmcquen
Copy link
Contributor Author

message: "CSSStyleSheet.cssRules getter: Not allowed to access cross-origin stylesheet"

@moughxyz
Copy link
Member

Hmm..probably not yet a good way to access these from JS. Why not use the var inside of a stylesheet? You can access all sn-stylekit-vars inside your stylesheet, even if they were loaded externally.

@ryanpcmcquen
Copy link
Contributor Author

I need to conditionally change the filter based on the value ... I don't think that is possible with CSS, but maybe there is a way to do it?

@ryanpcmcquen
Copy link
Contributor Author

@mobitar, so I'm trying a hack, where I make a hidden span, and assign its color to be --sn-stylekit-background-color, but it isn't populating. I thought the CSS vars were available ...

https://github.com/ryanpcmcquen/standardnotes_org_mode_editor/blob/gh-pages/styles.css
https://github.com/ryanpcmcquen/standardnotes_org_mode_editor/blob/gh-pages/index.html

@moughxyz
Copy link
Member

What do you mean by isn't populating? In my experience vars don't appear as resolved when using dev tools inspector. It will still say the variable name. This var in particular defaults to white.

@ryanpcmcquen
Copy link
Contributor Author

ryanpcmcquen commented Sep 15, 2020

I am reading the span using getComputedStyle(document.querySelector('.__data_from_root__')).color, but the value is always rgb(0, 0, 0).

I have tried switching between themes and refreshing the page, but the value never changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants