Update 'Disable Autoplaying Sounds' for Youtube videos.

This commit is contained in:
ccd0 2014-12-15 20:12:11 -08:00
parent 60266a686d
commit 0b2603412f
2 changed files with 18 additions and 0 deletions

View File

@ -107,6 +107,12 @@ audio.controls-added {
display: block;
margin: auto;
}
:root.anti-autoplay div.embed {
position: static;
width: auto;
height: auto;
text-align: center;
}
/* fixed, z-index */
#overlay,

View File

@ -1,8 +1,13 @@
AntiAutoplay =
init: ->
return if !Conf['Disable Autoplaying Sounds']
$.addClass doc, 'anti-autoplay'
@stop audio for audio in $$ 'audio[autoplay]', doc
window.addEventListener 'loadstart', ((e) => @stop e.target), true
Post.callbacks.push
name: 'Disable Autoplaying Sounds'
cb: @node
$.ready => @stopYoutube d.body
stop: (audio) ->
return unless audio.autoplay
@ -11,3 +16,10 @@ AntiAutoplay =
return if audio.controls
audio.controls = true
$.addClass audio, 'controls-added'
node: ->
AntiAutoplay.stopYoutube @nodes.root
stopYoutube: (root) ->
for iframe in $$ 'iframe[src*="youtube"][src*="autoplay=1"]', root
iframe.src = iframe.src.replace(/\?autoplay=1&?/, '?').replace('&autoplay=1', '')