MrOtherGuy / fx-autoconfig

Load custom javascript in browser context
Mozilla Public License 2.0
163 stars 10 forks source link

append style function ? #33

Open ricewind012 opened 11 months ago

ricewind012 commented 11 months ago

I think it would be nice to have a function that registers styles, kind of like GM_addStyle, if there isn't one already

MrOtherGuy commented 11 months ago

Well, there are example files to do that here although I think the agent sheet one won't actually work anymore because of Services import.

But it actually be reasonable to add that to utils since it already has a method to reload custom styles files.

MrOtherGuy commented 11 months ago

On second thought adding such method to utils isn't quite straigforward since agent and author styles must be injected very differently and thus implementing such a method isn't really something trivial. Requires some planning.

In the mean time I updated userChrome_ag_css (now as .sys.mjs module) so it should now work properly.

MrOtherGuy commented 11 months ago

What would the use-case be for such function in you opinion? Does it need to be a function to call?

I wonder if it could be declarative, i.e. the whole file would be for example my_style.uc.css and it could have exactly same kind of header your scripts would have. The header would then declare what documents it should affect or if it should instead be an agent sheet. Then the loader could correctly handle its injection itself.

MrOtherGuy commented 11 months ago

Well, we can't use exactly the same header because CSS doesn't support // line comments. But I could add separate parser for .uc.css files which could for example start with /* and end with */. In theory we could also trust that a {} after the header sequence would allow rest of the file to be parsed correctly by css parser, but that feels wrong (it works and is pretty simple to implement) but I'd rather not do that.

MrOtherGuy commented 11 months ago

So, with latest changes - that is loader version 0.8.5 - you can create a file such as the two examples here. No documentation exists yet, but the loader script will pick files named x.uc.css from CSS directory and load them automatically.

Note a slightly altered header format. Without any header the default style mode is author sheet and it is loaded into browser.xhtml - this is in line with handling of .uc.js scripts.

ricewind012 commented 11 months ago

What would the use-case be for such function in you opinion?

I am sorry I forgot I asked for this and my use case, the only one I can think of right now is for scripts with longer styles, maybe

Does it need to be a function to call?

this is what I originally intended, but what you did seems like a nicer way to do it

BTW, I tried updating, and it doesn't start until I make the CSS folder, doesn't fire an error about that either for me

MrOtherGuy commented 11 months ago

BTW, I tried updating, and it doesn't start until I make the CSS folder, doesn't fire an error about that either for me

Oh shoot, you are right. I think I fixed and tested this exact thing but apparently I didn't do it right.

So, now with b0fda8b this should really be fixed.