Add option for user CSS
This commit is contained in:
parent
a82745175e
commit
76c5baef6a
@ -11,6 +11,7 @@ type Settings struct {
|
||||
FluorideMode bool `json:"fluoride_mode"`
|
||||
DarkMode bool `json:"dark_mode"`
|
||||
AntiDopamineMode bool `json:"anti_dopamine_mode"`
|
||||
CSS string `json:"css"`
|
||||
}
|
||||
|
||||
func NewSettings() *Settings {
|
||||
@ -25,5 +26,6 @@ func NewSettings() *Settings {
|
||||
FluorideMode: false,
|
||||
DarkMode: false,
|
||||
AntiDopamineMode: false,
|
||||
CSS: "",
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ type Context struct {
|
||||
CSRFToken string
|
||||
UserID string
|
||||
AntiDopamineMode bool
|
||||
UserCSS string
|
||||
Referrer string
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@ func (s *service) authenticate(c *client, sid string, csrf string, ref string, t
|
||||
CSRFToken: c.s.CSRFToken,
|
||||
UserID: c.s.UserID,
|
||||
AntiDopamineMode: sett.AntiDopamineMode,
|
||||
UserCSS: sett.CSS,
|
||||
Referrer: ref,
|
||||
}
|
||||
}()
|
||||
@ -888,6 +889,9 @@ func (s *service) SaveSettings(c *client, settings *model.Settings) (err error)
|
||||
default:
|
||||
return errInvalidArgument
|
||||
}
|
||||
if len(settings.CSS) > 1<<20 {
|
||||
return errInvalidArgument
|
||||
}
|
||||
sess, err := s.sessionRepo.Get(c.s.ID)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -463,6 +463,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
||||
fluorideMode := c.r.FormValue("fluoride_mode") == "true"
|
||||
darkMode := c.r.FormValue("dark_mode") == "true"
|
||||
antiDopamineMode := c.r.FormValue("anti_dopamine_mode") == "true"
|
||||
css := c.r.FormValue("css")
|
||||
|
||||
settings := &model.Settings{
|
||||
DefaultVisibility: visibility,
|
||||
@ -475,6 +476,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
||||
FluorideMode: fluorideMode,
|
||||
DarkMode: darkMode,
|
||||
AntiDopamineMode: antiDopamineMode,
|
||||
CSS: css,
|
||||
}
|
||||
|
||||
err := s.SaveSettings(c, settings)
|
||||
|
@ -25,6 +25,9 @@
|
||||
{{if $.Ctx.FluorideMode}}
|
||||
<script src="/static/fluoride.js"></script>
|
||||
{{end}}
|
||||
{{if $.Ctx.UserCSS}}
|
||||
<style>{{$.Ctx.UserCSS}}</style>
|
||||
{{end}}
|
||||
</head>
|
||||
<body {{if $.Ctx.DarkMode}}class="dark"{{end}}>
|
||||
{{end}}
|
||||
|
@ -63,6 +63,12 @@
|
||||
<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="css"> Custom CSS: </label>
|
||||
</div>
|
||||
<div>
|
||||
<textarea id="css" name="css" cols="80" rows="8">{{.Settings.CSS}}</textarea>
|
||||
</div>
|
||||
<button type="submit"> Save </button>
|
||||
</form>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user