GithubHelp home page GithubHelp logo

Comments (6)

BoomerScratch avatar BoomerScratch commented on May 20, 2024

I think the only best way is to create a <style> element on the page. Although this "sandboxes" it, Stylus does basically the same.

from scratchaddons.

WorldLanguages avatar WorldLanguages commented on May 20, 2024

Yeah sure. The main thing to discuss is what APIs to provide so that userstyles don't have to be userscripts, and the addon manager can handle enabling or disabling them. We should specially discuss how to handle settings on userstyles.

from scratchaddons.

mxmou avatar mxmou commented on May 20, 2024

I think the only best way is to create a <style> element on the page. Although this "sandboxes" it, Stylus does basically the same.

Of course. One interesting thing is that Stylus actually inserts styles after the <body> element, not inside it.

The complicated part is settings and variables, for example in my userstyle. In the old discussion several options were mentioned:

  • To handle Boolean variables, the userstyle could be split into multiple CSS files: one which is always loaded, one for dark mode only and so on. This could be done manually.
  • Other variables (colors, numbers) could be converted to CSS variables. This could probably be automated but we would have to actually parse the Stylus code - simply replacing all instances of text in my userstyle with var(--addon-text) would also change text-align to var(--addon-text)-align.
  • Alternatively, Stylus code could be converted to CSS at runtime every time a setting is changed. This is my favorite option because it should be easy to implement: we won't need to write the Stylus preprocessor ourselves because it already exists and almost no conversion is needed to get the addon working (except replacing userstyle settings with addon settings, which is easy to do manually).

from scratchaddons.

WorldLanguages avatar WorldLanguages commented on May 20, 2024

IMO the last one is pretty complex, even tho I admit it is a great challenge and not the easy way.
Let's be real, userstyles won't change very much with time, and most of them are small userstyles.
I'd go for the first option and then the second if we want to let users customize things in the userstyle that aren't simple booleans.
The third option could still work tho, but until we want to add more than one Stylus userstyle I don't think the addon handler should need to consider Stylus code.

from scratchaddons.

BoomerScratch avatar BoomerScratch commented on May 20, 2024

One interesting thing is that Stylus actually inserts styles after the <body> element, not inside it.

Scratch doesn't delete the <style> elements so we can put it in the body or head without any problems.

from scratchaddons.

BoomerScratch avatar BoomerScratch commented on May 20, 2024

Wait, we have chrome.tabs.insertCSS. I don't really know if addon.tab.insertCSS exists; I don't have firefox.

from scratchaddons.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.