From a856b9d01bbaaa613d91c73c08816e47201133c4 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 24 Sep 2023 11:41:19 -0700 Subject: [PATCH] Blur explicit videos + GIF auto-play option --- pkg/controller/account/settings.go | 5 + web/static/js/bulma.js | 8 ++ web/templates/account/dashboard.html | 9 +- web/templates/account/settings.html | 14 +++ web/templates/forum/new_post.html | 164 +++++++++++++-------------- web/templates/photo/gallery.html | 10 +- web/templates/photo/permalink.html | 5 +- 7 files changed, 127 insertions(+), 88 deletions(-) diff --git a/pkg/controller/account/settings.go b/pkg/controller/account/settings.go index a39f647..45daf16 100644 --- a/pkg/controller/account/settings.go +++ b/pkg/controller/account/settings.go @@ -124,12 +124,17 @@ func Settings() http.HandlerFunc { var ( explicit = r.PostFormValue("explicit") == "true" blurExplicit = r.PostFormValue("blur_explicit") + autoplayGif = r.PostFormValue("autoplay_gif") ) user.Explicit = explicit // Set profile field prefs. user.SetProfileField("blur_explicit", blurExplicit) + if autoplayGif != "true" { + autoplayGif = "false" + } + user.SetProfileField("autoplay_gif", autoplayGif) if err := user.Save(); err != nil { session.FlashError(w, r, "Failed to save user to database: %s", err) diff --git a/web/static/js/bulma.js b/web/static/js/bulma.js index 4f13841..36d6a46 100644 --- a/web/static/js/bulma.js +++ b/web/static/js/bulma.js @@ -137,5 +137,13 @@ document.addEventListener('DOMContentLoaded', () => { e.stopPropagation(); } }); + + // Video tag: autoplay is disabled when blurred, onClick doesn't fire, + // set the handler for onPlay. + node.addEventListener("play", e => { + if (node.classList.contains("blurred-explicit")) { + node.classList.remove("blurred-explicit"); + } + }); }); }); diff --git a/web/templates/account/dashboard.html b/web/templates/account/dashboard.html index b956dd1..506c0d9 100644 --- a/web/templates/account/dashboard.html +++ b/web/templates/account/dashboard.html @@ -491,10 +491,13 @@ {{if $Body.PhotoID}} -
+
{{if HasSuffix $Body.Photo.Filename ".mp4"}} -
+
+ + +

+ Uncheck this box to disable auto-play on GIFs. +

+
+
- - - {{if .Forum.PermitPhotos}} - - {{end}} - {{end}} {{define "scripts"}} + + +{{if .Forum.PermitPhotos}} + +{{end}} + -{{end}} \ No newline at end of file +{{end}} diff --git a/web/templates/photo/gallery.html b/web/templates/photo/gallery.html index 3c09f68..3645a4d 100644 --- a/web/templates/photo/gallery.html +++ b/web/templates/photo/gallery.html @@ -403,7 +403,10 @@
{{if HasSuffix .Filename ".mp4"}} -