openstyles / stylus

Stylus - Userstyles Manager
https://add0n.com/stylus.html
GNU General Public License v3.0
5.35k stars 302 forks source link

[FR] Read styles from local filesystem #1252

Closed NightMachinery closed 10 months ago

NightMachinery commented 3 years ago

It would be very good if Stylus could read styles from a dir on the local filesystem, and apply the styles with hot reload. The options of a style can be put in the comments at the start of the CSS files.

For example, suppose Stylus is set to read the dir ~/userstyles/. I put this style there as ~/userstyles/x.css:

/* StylusConfigBeginToml
domain = "www.google.com" 
StylusConfigEnd */

#searchform * > div {
   width: auto;
   margin-left: auto;
}

Then Stylus automatically applies this style on www.google.com domains, with hot reload when the file changes.

This workflow has two major benefits:

Related:

tophf commented 3 years ago

One way to implement it is file:// access from the background script, but it won't work in Firefox. In Chrome we can do it, but there's no "onchange" event so all these file URLs would have to be re-checked every second which means 36,000 checks in ten hours per one file and that's just wasteful. In Chrome we could have used Native FileSystem API but yet again it won't work in Firefox. A universal solution could be nativeMessaging API that runs a separate external app, but none of us has been interested since Schomery tried to implement it four years ago. The idea per se is fine so the issue can stay open in case someone decides to take a stab at it.

P.S. The internal format of the files should be UserCSS, no need to reinvent the wheel.

NightMachinery commented 3 years ago

@tophf Polling is fine if we make it sth the user activates when they want to develop. We can optionally turn it off after three hours and show a notification.

tophf commented 3 years ago

On-demand polling is already implemented, see Writing UserCSS.

disco0 commented 3 years ago

On the topic of IDEs—thoughts on adding(/accepting a PR for) GhostText integration? There's some early discussion of an extension API using onConnectExternal/onMessageExternal. At least for userstyles, I'd gladly take Dropbox sync with live editing in VSCode over file:/// any day

vitaly-zdanevich commented 7 months ago

Not planned? The integrated editor is slow on my side :(

tophf commented 7 months ago

It's already implemented as "live reload", see Writing UserCSS.