diff --git a/main.go b/main.go index 0a3f775..42575a6 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,8 @@ func main() { c.String(200, "User-agent: *\nDisallow: /") }) + r.GET("/options/:name", routes.ChangeOptions) + r.GET("/", routes.GetHome) r.POST("/", routes.PostHome) diff --git a/public/home.css b/public/home.css index 57062ed..4554691 100644 --- a/public/home.css +++ b/public/home.css @@ -9,7 +9,6 @@ body { height: 100vh; width: 100vw; - overflow: hidden; margin: 0; color: white; @@ -78,6 +77,10 @@ body { margin: 0; } +.options { + margin-top: 1rem; +} + @media screen and (max-width: 800px) { body { padding: 1rem; diff --git a/src/routes/options.go b/src/routes/options.go new file mode 100644 index 0000000..795ad6c --- /dev/null +++ b/src/routes/options.go @@ -0,0 +1,25 @@ +package routes + +import ( + "fmt" + + "github.com/gin-gonic/gin" +) + +func ChangeOptions(c *gin.Context) { + name := c.Param("name") + + switch name { + case "images": + text := "disabled" + if c.MustGet("disable_images").(bool) { + text = "enabled" + } + c.SetCookie("disable_images", fmt.Sprintf("%t", !c.MustGet("disable_images").(bool)), 60*60*24*365*10, "/", "", false, true) + c.String(200, "Images are now %s", text) + default: + c.String(400, "400 Bad Request") + } + + c.Redirect(302, "/") +} diff --git a/templates/home.html b/templates/home.html index 57c61fd..8296117 100644 --- a/templates/home.html +++ b/templates/home.html @@ -36,6 +36,11 @@ +
+ Toggle Image Loading +