Minor refactor

This commit is contained in:
Omar Roth
2019-06-07 19:56:41 -05:00
parent f065a21542
commit 8c944815bc
18 changed files with 154 additions and 138 deletions

View File

@@ -1,5 +1,5 @@
function get_playlist(plid, timeouts = 0) {
if (timeouts > 10) {
function get_playlist(plid, timeouts = 1) {
if (timeouts >= 10) {
console.log('Failed to pull playlist');
return;
}
@@ -52,7 +52,7 @@ function get_playlist(plid, timeouts = 0) {
}
xhr.ontimeout = function () {
console.log('Pulling playlist timed out.');
console.log('Pulling playlist timed out... ' + timeouts + '/10');
get_playlist(plid, timeouts++);
}
}

View File

@@ -1,7 +1,7 @@
var notifications, delivered;
function get_subscriptions(callback, failures = 1) {
if (failures >= 10) {
function get_subscriptions(callback, timeouts = 1) {
if (timeouts >= 10) {
return
}
@@ -16,16 +16,13 @@ function get_subscriptions(callback, failures = 1) {
if (xhr.status === 200) {
subscriptions = xhr.response;
callback(subscriptions);
} else {
console.log('Pulling subscriptions failed... ' + failures + '/10');
get_subscriptions(callback, failures++)
}
}
}
xhr.ontimeout = function () {
console.log('Pulling subscriptions failed... ' + failures + '/10');
get_subscriptions(callback, failures++);
console.log('Pulling subscriptions timed out... ' + timeouts + '/10');
get_subscriptions(callback, timeouts++);
}
}

View File

@@ -1,20 +1,20 @@
var options = {
preload: "auto",
preload: 'auto',
liveui: true,
playbackRates: [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2.0],
controlBar: {
children: [
"playToggle",
"volumePanel",
"currentTimeDisplay",
"timeDivider",
"durationDisplay",
"progressControl",
"remainingTimeDisplay",
"captionsButton",
"qualitySelector",
"playbackRateMenuButton",
"fullscreenToggle"
'playToggle',
'volumePanel',
'currentTimeDisplay',
'timeDivider',
'durationDisplay',
'progressControl',
'remainingTimeDisplay',
'captionsButton',
'qualitySelector',
'playbackRateMenuButton',
'fullscreenToggle'
]
}
}
@@ -29,7 +29,7 @@ short_url = location.origin + '/' + video_data.id + embed_url.search;
embed_url = location.origin + '/embed/' + video_data.id + embed_url.search;
var shareOptions = {
socials: ["fbFeed", "tw", "reddit", "email"],
socials: ['fbFeed', 'tw', 'reddit', 'email'],
url: short_url,
title: player_data.title,
@@ -38,7 +38,7 @@ var shareOptions = {
embedCode: "<iframe id='ivplayer' type='text/html' width='640' height='360' src='" + embed_url + "' frameborder='0'></iframe>"
}
var player = videojs("player", options, function () {
var player = videojs('player', options, function () {
this.hotkeys({
volumeStep: 0.1,
seekStep: 5,

View File

@@ -7,7 +7,7 @@ if (subscribe_button.getAttribute('data-type') === 'subscribe') {
subscribe_button.onclick = unsubscribe;
}
function subscribe(timeouts = 0) {
function subscribe(timeouts = 1) {
if (timeouts >= 10) {
console.log('Failed to subscribe.');
return;
@@ -19,7 +19,7 @@ function subscribe(timeouts = 0) {
xhr.responseType = 'json';
xhr.timeout = 20000;
xhr.open('POST', url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send('csrf_token=' + subscribe_data.csrf_token);
var fallback = subscribe_button.innerHTML;
@@ -36,12 +36,12 @@ function subscribe(timeouts = 0) {
}
xhr.ontimeout = function () {
console.log('Subscribing timed out.');
console.log('Subscribing timed out... ' + timeouts + '/10');
subscribe(timeouts++);
}
}
function unsubscribe(timeouts = 0) {
function unsubscribe(timeouts = 1) {
if (timeouts >= 10) {
console.log('Failed to subscribe');
return;
@@ -70,7 +70,7 @@ function unsubscribe(timeouts = 0) {
}
xhr.ontimeout = function () {
console.log('Unsubscribing timed out.');
console.log('Unsubscribing timed out... ' + timeouts + '/10');
unsubscribe(timeouts++);
}
}

View File

@@ -109,10 +109,10 @@ function number_with_separator(val) {
return val;
}
function get_playlist(plid, timeouts = 0) {
function get_playlist(plid, timeouts = 1) {
playlist = document.getElementById('playlist');
if (timeouts > 10) {
if (timeouts >= 10) {
console.log('Failed to pull playlist');
playlist.innerHTML = '';
return;
@@ -175,18 +175,19 @@ function get_playlist(plid, timeouts = 0) {
}
xhr.ontimeout = function () {
console.log('Pulling playlist timed out.');
playlist = document.getElementById('playlist');
playlist.innerHTML =
'<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3><hr>';
get_playlist(plid, timeouts + 1);
console.log('Pulling playlist timed out... ' + timeouts + '/10');
get_playlist(plid, timeouts++);
}
}
function get_reddit_comments(timeouts = 0) {
function get_reddit_comments(timeouts = 1) {
comments = document.getElementById('comments');
if (timeouts > 10) {
if (timeouts >= 10) {
console.log('Failed to pull comments');
comments.innerHTML = '';
return;
@@ -238,7 +239,8 @@ function get_reddit_comments(timeouts = 0) {
comments.children[0].children[1].children[0].onclick = swap_comments;
} else {
if (video_data.params.comments[1] === 'youtube') {
get_youtube_comments(timeouts + 1);
console.log('Pulling comments timed out... ' + timeouts + '/10');
get_youtube_comments(timeouts++);
} else {
comments.innerHTML = fallback;
}
@@ -247,15 +249,15 @@ function get_reddit_comments(timeouts = 0) {
}
xhr.ontimeout = function () {
console.log('Pulling comments timed out.');
get_reddit_comments(timeouts + 1);
console.log('Pulling comments timed out... ' + timeouts + '/10');
get_reddit_comments(timeouts++);
}
}
function get_youtube_comments(timeouts = 0) {
function get_youtube_comments(timeouts = 1) {
comments = document.getElementById('comments');
if (timeouts > 10) {
if (timeouts >= 10) {
console.log('Failed to pull comments');
comments.innerHTML = '';
return;
@@ -303,7 +305,7 @@ function get_youtube_comments(timeouts = 0) {
comments.children[0].children[1].children[0].onclick = swap_comments;
} else {
if (video_data.params.comments[1] === 'youtube') {
get_youtube_comments(timeouts + 1);
get_youtube_comments(timeouts++);
} else {
comments.innerHTML = '';
}
@@ -312,10 +314,10 @@ function get_youtube_comments(timeouts = 0) {
}
xhr.ontimeout = function () {
console.log('Pulling comments timed out.');
comments.innerHTML =
'<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3>';
get_youtube_comments(timeouts + 1);
console.log('Pulling comments timed out... ' + timeouts + '/10');
get_youtube_comments(timeouts++);
}
}

View File

@@ -22,7 +22,7 @@ function mark_watched(target) {
function mark_unwatched(target) {
var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode;
tile.style.display = "none";
tile.style.display = 'none';
var count = document.getElementById('count')
count.innerText = count.innerText - 1;