diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 5c5c06a25..5a652de91 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -247,7 +247,7 @@ Config = ] 'Allow Sound': [ true - 'Allow sound in videos.' + 'Open videos with the sound unmuted.' ] 'Loop in New Tab': [ true @@ -560,6 +560,8 @@ Config = 6.0 ] + 'Default Volume': 1.0 + threadWatcher: 'Current Board': [ false diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 57ad987e6..6ed37aec1 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -338,6 +338,7 @@ Main = ['Reveal Spoiler Thumbnails', RevealSpoilers] ['Image Loading', ImageLoader] ['Image Hover', ImageHover] + ['Volume Control', Volume] ['Comment Expansion', ExpandComment] ['Thread Expansion', ExpandThread] ['Thread Excerpt', ThreadExcerpt] diff --git a/src/General/css/style.css b/src/General/css/style.css index 4cd9884e2..be473d727 100755 --- a/src/General/css/style.css +++ b/src/General/css/style.css @@ -928,6 +928,12 @@ span.hide-announcement { .fileThumb > .warning { clear: both; } +input[name="Default Volume"] { + width: 4em; + height: 1ex; + vertical-align: middle; + margin: 0px; +} /* Fappe Tyme */ :root.fappeTyme .thread > .noFile, :root.fappeTyme .threadContainer > .noFile { diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index b3c949d36..2547fac91 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -156,7 +156,7 @@ Gallery = $.replace nodes.current, file if elType is 'video' file.loop = true - file.muted = !Conf['Allow Sound'] + Volume.setup file file.play() if Conf['Autoplay'] ImageCommon.addControls file if Conf['Show Controls'] nodes.count.textContent = +thumb.dataset.id + 1 diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index a73813ca5..be64c5ff9 100755 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -28,7 +28,7 @@ ImageExpand = ImageExpand.expand @ else if @file.isExpanded and @file.isVideo - @file.fullImage.muted = !Conf['Allow Sound'] + Volume.setup @file.fullImage ImageExpand.setupVideo @, !@origin.file.fullImage?.paused or @origin.file.wasPlaying, @file.fullImage.controls else if ImageExpand.on and !@isHidden and !@isFetchedQuote and @@ -168,6 +168,7 @@ ImageExpand = ImageCommon.rewind el if Conf['Restart when Opened'] and el.id isnt 'ihover' el.removeAttribute 'id' else + isNew = true el = file.fullImage = $.el (if isVideo then 'video' else 'img') el.dataset.fullID = post.fullID $.on el, 'error', ImageExpand.error @@ -182,7 +183,7 @@ ImageExpand = thumb.parentNode.removeAttribute 'target' el.loop = true - el.muted = !Conf['Allow Sound'] + Volume.setup el, isNew if !isVideo $.asap (-> el.naturalHeight), -> ImageExpand.completeExpand post diff --git a/src/Images/ImageHover.coffee b/src/Images/ImageHover.coffee index 3f3e8cb8b..e1093dd12 100755 --- a/src/Images/ImageHover.coffee +++ b/src/Images/ImageHover.coffee @@ -29,6 +29,7 @@ ImageHover = el = ImageCommon.popCache() $.on el, 'error', error else + isNew = true el = $.el (if isVideo then 'video' else 'img') el.dataset.fullID = post.fullID $.on el, 'error', error @@ -42,7 +43,7 @@ ImageHover = if isVideo el.loop = true el.controls = false - el.muted = !Conf['Allow Sound'] + Volume.setup el, isNew el.play() if Conf['Autoplay'] [width, height] = (+x for x in file.dimensions.split 'x') {left, right} = @getBoundingClientRect() diff --git a/src/Images/Volume.coffee b/src/Images/Volume.coffee new file mode 100644 index 000000000..acc32365f --- /dev/null +++ b/src/Images/Volume.coffee @@ -0,0 +1,42 @@ +Volume = + init: -> + return unless g.BOARD.ID in ['gif', 'wsg'] and + g.VIEW in ['index', 'thread'] and + (Conf['Image Expansion'] or Conf['Image Hover'] or Conf['Image Hover in Catalog'] or Conf['Gallery']) + + unmuteEntry = UI.checkbox 'Allow Sound', ' Allow Sound' + unmuteEntry.title = Config.main['Images and Videos']['Allow Sound'][1] + + volumeEntry = $.el 'label', + title: 'Default volume for videos.' + $.extend volumeEntry, + <%= html(' Volume') %> + + @inputs = + unmute: unmuteEntry.firstElementChild + volume: volumeEntry.firstElementChild + + $.on @inputs.unmute, 'change', $.cb.checked + $.on @inputs.volume, 'change', $.cb.value + + $.sync 'Allow Sound', (x) -> Volume.inputs.unmute.checked = x + $.sync 'Default Volume', (x) -> Volume.inputs.volume.value = x + + Header.menu.addEntry {el: unmuteEntry, order: 200} + Header.menu.addEntry {el: volumeEntry, order: 201} + + setup: (video, isNew=true) -> + video.muted = !Conf['Allow Sound'] + video.volume = Conf['Default Volume'] + $.on video, 'volumechange', Volume.onchange if isNew + + onchange: -> + {muted, volume} = @ + items = + 'Allow Sound': !muted + 'Default Volume': volume + $.set items + $.extend Conf, items + if Volume.inputs + Volume.inputs.unmute.checked = !muted + Volume.inputs.volume.value = volume