feat: change options

This commit is contained in:
httpjamesm 2022-12-28 00:08:06 -05:00
parent 8b46beb1dd
commit 10946dcafb
4 changed files with 36 additions and 1 deletions

View File

@ -22,6 +22,8 @@ func main() {
c.String(200, "User-agent: *\nDisallow: /") c.String(200, "User-agent: *\nDisallow: /")
}) })
r.GET("/options/:name", routes.ChangeOptions)
r.GET("/", routes.GetHome) r.GET("/", routes.GetHome)
r.POST("/", routes.PostHome) r.POST("/", routes.PostHome)

View File

@ -9,7 +9,6 @@ body {
height: 100vh; height: 100vh;
width: 100vw; width: 100vw;
overflow: hidden;
margin: 0; margin: 0;
color: white; color: white;
@ -78,6 +77,10 @@ body {
margin: 0; margin: 0;
} }
.options {
margin-top: 1rem;
}
@media screen and (max-width: 800px) { @media screen and (max-width: 800px) {
body { body {
padding: 1rem; padding: 1rem;

25
src/routes/options.go Normal file
View File

@ -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, "/")
}

View File

@ -36,6 +36,11 @@
<button class="view-button" type="submit">View</button> <button class="view-button" type="submit">View</button>
</div> </div>
</form> </form>
<div class="options">
<a class="toggle" href="/options/images"
>Toggle Image Loading</a
>
</div>
<p class="footer"> <p class="footer">
Brought to you by Brought to you by
<a <a