Custom (per-user) CSS. master
authorPete <pete@debu.gs>
Sat, 3 Apr 2021 07:48:02 +0000 (00:48 -0700)
committerPete <pete@debu.gs>
Sat, 3 Apr 2021 07:48:02 +0000 (00:48 -0700)
Should probably rename to avoid confusion with custom (per-site) CSS,
which I only noticed when looking at the diff.

model/settings.go
renderer/model.go
service/service.go
service/transport.go
templates/header.tmpl
templates/settings.tmpl

index 6d179018baf6c1c970b9c3189461a6cb8fb53f84..9b4ff3f768d8fb4eaa4528a3273b872dd8a35602 100644 (file)
@@ -11,6 +11,7 @@ type Settings struct {
        FluorideMode         bool   `json:"fluoride_mode"`
        DarkMode             bool   `json:"dark_mode"`
        AntiDopamineMode     bool   `json:"anti_dopamine_mode"`
+       CustomCSS            string `json:"custom_css"`
 }
 
 func NewSettings() *Settings {
@@ -25,5 +26,6 @@ func NewSettings() *Settings {
                FluorideMode:         false,
                DarkMode:             false,
                AntiDopamineMode:     false,
+               CustomCSS:            "",
        }
 }
index a89b3792f4e9c4d09e83a48c8c83cf1a0230bd16..9df4eb6d7791ba3bbff23e5771bf572b8158f7ff 100644 (file)
@@ -14,6 +14,7 @@ type Context struct {
        CSRFToken        string
        UserID           string
        AntiDopamineMode bool
+       CustomCSS        string
        Referrer         string
 }
 
index a69af56897d1fdd7c8dafd36fc11ffb519072178..3803be42cc2e5329f0bf11d8a8d0d39ed31d29dc 100644 (file)
@@ -77,6 +77,7 @@ func getRendererContext(c *client) *renderer.Context {
                CSRFToken:        session.CSRFToken,
                UserID:           session.UserID,
                AntiDopamineMode: settings.AntiDopamineMode,
+               CustomCSS:        settings.CustomCSS,
                Referrer:         referrer,
        }
 }
index 882a35130a85de258cb43857be7c10c7079962bd..6b676cf649986a7deba662efb6cdf043ea8f0db6 100644 (file)
@@ -498,6 +498,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
                fluorideMode := c.Req.FormValue("fluoride_mode") == "true"
                darkMode := c.Req.FormValue("dark_mode") == "true"
                antiDopamineMode := c.Req.FormValue("anti_dopamine_mode") == "true"
+               customCSS := c.Req.FormValue("custom_css")
 
                settings := &model.Settings{
                        DefaultVisibility:    visibility,
@@ -510,6 +511,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
                        FluorideMode:         fluorideMode,
                        DarkMode:             darkMode,
                        AntiDopamineMode:     antiDopamineMode,
+                       CustomCSS:            customCSS,
                }
 
                err := s.SaveSettings(c, settings)
index df2b6afbb626552ce1c670e9c5d828c75eb1572e..095dc616d036ea5f1eaee86d6708acf7609f6fd7 100644 (file)
@@ -25,6 +25,9 @@
        {{if $.Ctx.FluorideMode}}
        <script src="/static/fluoride.js"></script>
        {{end}}
+       {{if $.Ctx.CustomCSS}}
+       <style>{{$.Ctx.CustomCSS}}</style>
+       {{end}}
 </head>
 <body {{if $.Ctx.DarkMode}}class="dark"{{end}}>
 {{end}}
index 4a72b6ab10004aa969500c4ce88a475234f080af..e2287305ac6f94b0fa750fbe00f546ef3a4ec065 100644 (file)
                <input id="dark-mode" name="dark_mode" type="checkbox" value="true" {{if .Settings.DarkMode}}checked{{end}}>
                <label for="dark-mode"> Use dark theme </label>
        </div>
+       <div class="settings-form-field">
+               <label for="custom-css">Custom CSS:</label>
+               <textarea id="custom-css" name="custom_css" cols="80" rows="24">{{.Settings.CustomCSS}}</textarea>
+       </div>
        <button type="submit"> Save </button>
 </form>