openstyles / stylus

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

Accessing a userstyle to replace variables #680

Closed goteksc closed 5 years ago

goteksc commented 5 years ago

Now, the question is, is there a way for me to change variables inside a style or user.css applied with stylus with a bash script? IE: Are the styles put into a local dir that I was just too dumb to find?

Or is it possible to set stylus to update a user.css on startup or a really short interval? (seconds) That way I could automatically push to a repo containing the user.css with updated color variables.

Why would I want that?

I'm using wpgtk, (pywal has similar functionality) which among other things outputs out a colors.css file which looks like this: colors.css

/* CSS variables
   Generated by 'wal' */
:root {
    --wallpaper: url("/home/gotek/.config/wpg/wallpapers/osaka-rain.jpg");

    /* Special */
    --background: #0a121b;
    --foreground: #ffeaff;
    --cursor: #ffeaff;

    /* Colors */
    --color0: #0a121b;
    --color1: #A19DE0;
    --color2: #5A609F;
    --color3: #BEC0B6;
    --color4: #3E6CCF;
    --color5: #B35AC4;
    --color6: #529DD5;
    --color7: #e4c9ec;
    --color8: #162a40;
    --color9: #bbb3ff;
    --color10: #646fde;
    --color11: #ffffd4;
    --color12: #3f85ff;
    --color13: #f562ff;
    --color14: #57ceff;
    --color15: #ffeaff;
}

I'm appending this, together with custom css into the userChrome.css file of Firefox to update the color scheme of the browser with every use of wpgtk.

cat ~/.config/wpg/formats/colors.css ~/.scripts/firefoxwpg/firefoxTheme.css > ~/.mozilla/firefox/myprofile/chrome/userChrome.css

This is launched as a postscript when I change the color scheme/wallpaper with wpgtk. I tried replicating that approach for duckduckgo.com with the userContent.css file for firefox, but duckduckgo has some wonky priority in loading first it's default theme, then respecting userContent.css and afterwards loading a custom theme (if set) ontop.

I found more success applying my custom css onto duckduckgo with Stylus.

eight04 commented 5 years ago

You can build a .user.css file and tell Firefox to open the file. But you still have to click the "Install" button to update the userstyle.

Not sure if it is possible to simplify this process. I think it doesn't worth creating a native app to handle this.

Actually, it might be easier to output your variables to clipboard, then open the editor in Stylus -> paste the code -> save the style.

goteksc commented 5 years ago

So, since you didn't bring it up, I guess stylus stores it's data in a containerfile somewhere in the browser profile, right? The .user.css themselves aren't available as raw text files?

Note: I'm not familiar with webextension development, nor am I a programmer.

You can build a .user.css file and tell Firefox to open the file. But you still have to click the "Install" button to update the userstyle.

I guess I have to live with that. Rarely change wallpaper/color scheme more than once a day anyways. Do I need to do as stated in https://github.com/openstyles/stylus/wiki/UserCSS-authors#hosting-a-usercss, or is it possible to point to a local directory?

Mottie commented 5 years ago

stylus stores it's data in a containerfile

There is a built-in browser database which can be used; but it's not accessible at all times (private browsing). And yes we do save the original raw text file along with parsed data.

is it possible to point to a local directory?

You can install usercss files from a local directory.

goteksc commented 5 years ago

There is a built-in browser database which can be used

Does this mean there is a file somewhere in the firefox profile directory that I could manipulate with a bash script to update the color variables of a usercss?

You can install usercss files from a local directory.

What I was referring to was the ability to update usercss though stylus, either automatically or on demand. Is that possible with a usercss that is stored locally?

Mottie commented 5 years ago

It's saved as an SQLite file (check the reference for location), so I don't think you can modify it using bash, but that's outside my realm of knowledge,

Also check out https://www.jeffersonscher.com/res/stylishextract.html, referenced from https://github.com/openstyles/stylus/issues/77#issuecomment-324156420.

goteksc commented 5 years ago

Thanks for the swift responses!

so I don't think you can modify it using bash

Yeah, I think so too, or at least learning SQlite is out of the scope of this little project of mine.

niksingh710 commented 5 months ago

is this in consideration as with pywalfox?