Per-gebruiker CSS toevoegen in een plugin?

In een plugin, hoe voegt men per gebruiker CSS toe? Bijvoorbeeld veroorzaakt door een gebruikersinstelling?

Het toevoegen van de stijlen en dergelijke aan elementen/via stylesheets zou globaal zijn, nietwaar?

Wat probeer je te doen? Je kunt dingen zoals de kleur van individuele gebruikersnamen/vermeldingen veranderen, gewoon via de normale themacss. Als je bedoelt, een specifiek deel van een thema veranderen met een schakelaar via de voorkeuren van een specifieke gebruiker, dan geloof ik niet dat je dat zou kunnen doen zonder hen hun eigen thema te geven. Ik ben echter geen expert.

2 likes

Zoals bijvoorbeeld, een instelling per gebruiker om lettertypen van bepaalde dingen te wijzigen (bijv. de Markdown-editor).

You could offer groups that the user can join and use CSS Classes for Current User's Groups.

Or the user can use a browser plugin to change CSS only for themselves. I use Stylus to customize my experience on Meta.

Was the composer a random example? Or what do you want to offer in addition to “Use monospace font in composer’s Markdown mode,” which can be enabled or disabled in the preferences?

1 like

Kinda. I was thinking how the font would be changed per-user.

1 like

You can probably achieve this in a plugin by doing something along the lines of:

  • with the plugin API add a api.addSaveableUserOptionField("composer-custom-font")
  • add the field to the UserOption table in the db and the serializer so it can be set
  • add a connector to the user’s interface page so the setting can be set
  • you can make the setting a dropdown, for example, so if the user picks a certain font/font style it adds their preference in the db
  • you can extend the composer code to take into account their selected preference, and either change the styles directly with JS or make it add a CSS class based on the preference chosen, which you can apply styles via CSS for that specific class
2 likes