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