Add local setting to enable audio on videos by default (#252)

* Add local setting to enable audio on videos by default

* Update copy

* Use ternary over `let`+`if`
This commit is contained in:
Eliot Partridge 2024-05-05 17:38:22 -04:00 committed by GitHub
parent 5b836580e1
commit 377317a26b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

View file

@ -86,10 +86,12 @@ function pickAndResize(elem) {
clearEl(elem);
}
const muted = store.get('unmute_videos') ? '' : 'muted';
if (imageFormat === 'mp4') {
elem.classList.add('full-height');
elem.insertAdjacentHTML('afterbegin',
`<video controls autoplay loop muted playsinline preload="auto" id="image-display"
`<video controls autoplay loop ${muted} playsinline preload="auto" id="image-display"
width="${imageWidth}" height="${imageHeight}">
<source src="${uris.webm}" type="video/webm">
<source src="${uris.mp4}" type="video/mp4">
@ -102,7 +104,7 @@ function pickAndResize(elem) {
}
else if (imageFormat === 'webm') {
elem.insertAdjacentHTML('afterbegin',
`<video controls autoplay loop muted playsinline id="image-display">
`<video controls autoplay loop ${muted} playsinline id="image-display">
<source src="${uri}" type="video/webm">
<source src="${uri.replace(/webm$/, 'mp4')}" type="video/mp4">
<p class="block block--fixed block--warning">

View file

@ -39,6 +39,7 @@ defmodule PhilomenaWeb.SettingController do
|> set_cookie(user_params, "hidpi", "hidpi")
|> set_cookie(user_params, "webm", "webm")
|> set_cookie(user_params, "serve_webm", "serve_webm")
|> set_cookie(user_params, "unmute_videos", "unmute_videos")
|> set_cookie(user_params, "chan_nsfw", "chan_nsfw")
|> set_cookie(user_params, "hide_staff_tools", "hide_staff_tools")
|> set_cookie(user_params, "hide_uploader", "hide_uploader")

View file

@ -154,6 +154,10 @@ h1 Content Settings
=> label f, :webm, "Use video thumbnails"
=> checkbox f, :webm, checked: @conn.cookies["webm"] == "true"
.fieldlabel: i Use video thumbnails for WebM videos. Does not apply to GIF images.
.field
=> label f, :unmute_videos, "Enable video audio by default"
=> checkbox f, :unmute_videos, checked: @conn.cookies["unmute_videos"] == "true"
.fieldlabel: i Automatically enable audio on video pages when they are loaded.
.field
=> label f, :hide_uploader
=> checkbox f, :hide_uploader, checked: @conn.cookies["hide_uploader"] == "true"