Add continuous playback

This commit is contained in:
Omar Roth
2018-11-11 11:45:05 -06:00
parent 1465cefa17
commit 4b76b93610
5 changed files with 69 additions and 1 deletions

View File

@@ -23,6 +23,11 @@ function update_value(element) {
<input name="autoplay" id="autoplay" type="checkbox" <% if user.preferences.autoplay %>checked<% end %>>
</div>
<div class="pure-control-group">
<label for="continue">Automatically play next video: </label>
<input name="continue" id="continue" type="checkbox" <% if user.preferences.continue %>checked<% end %>>
</div>
<div class="pure-control-group">
<label for="listen">Listen by default: </label>
<input name="listen" id="listen" type="checkbox" <% if user.preferences.listen %>checked<% end %>>

View File

@@ -140,6 +140,15 @@
<% if !preferences || preferences && preferences.related_videos %>
<div class="h-box">
<% if !plid && !rvs.empty? %>
<div class="pure-control-group">
<label for="continue">Autoplay next video: </label>
<input name="continue" onclick="continue_autoplay(this)" id="continue" type="checkbox" <% if params[:continue] %>checked<% end %>>
</div>
<hr>
<% end %>
<% rvs.each do |rv| %>
<% if rv.has_key?("id") %>
<a href="/watch?v=<%= rv["id"] %>">
@@ -163,6 +172,46 @@
</div>
<script>
<% if !rvs.empty? && !plid && params[:continue] %>
player.on('ended', function() {
window.location.replace("/watch?v="
+ "<%= rvs[0]?.try &.["id"] %>"
+ "&continue=1"
<% if params[:listen] %>
+ "&listen=1"
<% end %>
<% if params[:autoplay] %>
+ "&autoplay=1"
<% end %>
<% if params[:speed] %>
+ "&speed=<%= params[:speed] %>"
<% end %>
);
});
<% end %>
function continue_autoplay(target) {
if (target.checked) {
player.on('ended', function() {
window.location.replace("/watch?v="
+ "<%= rvs[0]?.try &.["id"] %>"
+ "&continue=1"
<% if params[:listen] %>
+ "&listen=1"
<% end %>
<% if params[:autoplay] %>
+ "&autoplay=1"
<% end %>
<% if params[:speed] %>
+ "&speed=<%= params[:speed] %>"
<% end %>
);
});
} else {
player.off('ended');
}
}
function number_with_separator(val) {
while (/(\d+)(\d{3})/.test(val.toString())) {
val = val.toString().replace(/(\d+)(\d{3})/, "$1" + "," + "$2");