2022-04-20 08:38:24 +00:00
|
|
|
|
'use strict';
|
2019-05-06 14:48:33 +00:00
|
|
|
|
|
2018-10-07 03:20:40 +00:00
|
|
|
|
function toggle_parent(target) {
|
2022-04-20 10:23:24 +00:00
|
|
|
|
var body = target.parentNode.parentNode.children[1];
|
2022-05-06 01:46:59 +00:00
|
|
|
|
if (body.style.display === 'none') {
|
2022-04-20 10:42:34 +00:00
|
|
|
|
target.textContent = '[ − ]';
|
2019-05-06 14:48:33 +00:00
|
|
|
|
body.style.display = '';
|
2022-05-06 01:46:59 +00:00
|
|
|
|
} else {
|
|
|
|
|
target.textContent = '[ + ]';
|
|
|
|
|
body.style.display = 'none';
|
2019-05-02 01:03:39 +00:00
|
|
|
|
}
|
2018-10-07 03:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 18:30:30 +00:00
|
|
|
|
function swap_comments(event) {
|
|
|
|
|
var source = event.target.getAttribute('data-comments');
|
|
|
|
|
|
|
|
|
|
if (source === 'youtube') {
|
2019-05-02 01:03:39 +00:00
|
|
|
|
get_youtube_comments();
|
2019-05-15 18:30:30 +00:00
|
|
|
|
} else if (source === 'reddit') {
|
2019-05-02 01:03:39 +00:00
|
|
|
|
get_reddit_comments();
|
|
|
|
|
}
|
2018-10-07 03:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 16:23:14 +00:00
|
|
|
|
var continue_button = document.getElementById('continue');
|
2019-05-14 13:18:57 +00:00
|
|
|
|
if (continue_button) {
|
|
|
|
|
continue_button.onclick = continue_autoplay;
|
|
|
|
|
}
|
2019-05-06 16:23:14 +00:00
|
|
|
|
|
2019-08-16 21:01:14 +00:00
|
|
|
|
function next_video() {
|
|
|
|
|
var url = new URL('https://example.com/watch?v=' + video_data.next_video);
|
2019-05-06 14:48:33 +00:00
|
|
|
|
|
2022-05-06 01:46:59 +00:00
|
|
|
|
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
2019-08-16 21:01:14 +00:00
|
|
|
|
url.searchParams.set('autoplay', '1');
|
2022-05-06 01:46:59 +00:00
|
|
|
|
if (video_data.params.listen !== video_data.preferences.listen)
|
2019-08-16 21:01:14 +00:00
|
|
|
|
url.searchParams.set('listen', video_data.params.listen);
|
2022-05-06 01:46:59 +00:00
|
|
|
|
if (video_data.params.speed !== video_data.preferences.speed)
|
2019-08-16 21:01:14 +00:00
|
|
|
|
url.searchParams.set('speed', video_data.params.speed);
|
2022-05-06 01:46:59 +00:00
|
|
|
|
if (video_data.params.local !== video_data.preferences.local)
|
2019-08-16 21:01:14 +00:00
|
|
|
|
url.searchParams.set('local', video_data.params.local);
|
|
|
|
|
url.searchParams.set('continue', '1');
|
2022-05-06 01:46:59 +00:00
|
|
|
|
|
2019-08-16 21:01:14 +00:00
|
|
|
|
location.assign(url.pathname + url.search);
|
|
|
|
|
}
|
2019-05-27 17:16:22 +00:00
|
|
|
|
|
2019-08-16 21:01:14 +00:00
|
|
|
|
function continue_autoplay(event) {
|
|
|
|
|
if (event.target.checked) {
|
2022-05-06 01:46:59 +00:00
|
|
|
|
player.on('ended', next_video);
|
2019-05-06 14:48:33 +00:00
|
|
|
|
} else {
|
|
|
|
|
player.off('ended');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-29 06:48:43 +00:00
|
|
|
|
function get_compilation(compid) {
|
2023-08-05 09:53:36 +00:00
|
|
|
|
var compilation = document.getElementById('compilation');
|
2023-06-29 06:48:43 +00:00
|
|
|
|
|
|
|
|
|
compilation.innerHTML = spinnerHTMLwithHR;
|
|
|
|
|
|
|
|
|
|
var compid_url;
|
|
|
|
|
compid_url = '/api/v1/compilations/' + compid +
|
|
|
|
|
'?index=' + video_data.index +
|
|
|
|
|
'&continuation=' + video_data.id +
|
2023-08-06 08:39:29 +00:00
|
|
|
|
'&format=html&hl=' + video_data.preferences.locale;
|
2023-06-29 06:48:43 +00:00
|
|
|
|
|
|
|
|
|
helpers.xhr('GET', compid_url, {retries: 5, entity_name: 'compilation'}, {
|
|
|
|
|
on200: function (response) {
|
|
|
|
|
compilation.innerHTML = response.compilationHtml;
|
|
|
|
|
|
2023-08-05 09:53:36 +00:00
|
|
|
|
if (!response.nextVideo) return;
|
2023-06-29 06:48:43 +00:00
|
|
|
|
|
2023-08-05 09:53:36 +00:00
|
|
|
|
var nextVideo = document.getElementById(response.nextVideo);
|
|
|
|
|
nextVideo.parentNode.parentNode.scrollTop = nextVideo.offsetTop;
|
2023-06-29 06:48:43 +00:00
|
|
|
|
|
2023-08-05 09:53:36 +00:00
|
|
|
|
player.on('ended', function () {
|
|
|
|
|
var url = new URL('https://example.com/watch?v=' + response.nextVideo);
|
2023-06-29 06:48:43 +00:00
|
|
|
|
|
2023-12-04 02:44:07 +00:00
|
|
|
|
url.searchParams.set('comp', compid);
|
2023-08-05 09:53:36 +00:00
|
|
|
|
if (!compid.startsWith('RD'))
|
|
|
|
|
url.searchParams.set('index', response.index);
|
|
|
|
|
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
|
|
|
|
url.searchParams.set('autoplay', '1');
|
|
|
|
|
if (video_data.params.listen !== video_data.preferences.listen)
|
|
|
|
|
url.searchParams.set('listen', video_data.params.listen);
|
|
|
|
|
if (video_data.params.speed !== video_data.preferences.speed)
|
|
|
|
|
url.searchParams.set('speed', video_data.params.speed);
|
|
|
|
|
if (video_data.params.local !== video_data.preferences.local)
|
|
|
|
|
url.searchParams.set('local', video_data.params.local);
|
2023-08-06 00:42:10 +00:00
|
|
|
|
url.searchParams.set('t',video_data.starting_timestamp_seconds);
|
2023-08-06 07:59:53 +00:00
|
|
|
|
url.searchParams.set('end',video_data.ending_timestamp_seconds);
|
2023-06-29 06:48:43 +00:00
|
|
|
|
|
2023-08-05 09:53:36 +00:00
|
|
|
|
location.assign(url.pathname + url.search);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onNon200: function (xhr) {
|
|
|
|
|
compilation.innerHTML = '';
|
|
|
|
|
document.getElementById('continue').style.display = '';
|
|
|
|
|
},
|
|
|
|
|
onError: function (xhr) {
|
|
|
|
|
compilation.innerHTML = spinnerHTMLwithHR;
|
|
|
|
|
},
|
|
|
|
|
onTimeout: function (xhr) {
|
|
|
|
|
compilation.innerHTML = spinnerHTMLwithHR;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-06-29 06:48:43 +00:00
|
|
|
|
|
2022-05-06 01:46:59 +00:00
|
|
|
|
function get_playlist(plid) {
|
2022-04-20 10:23:24 +00:00
|
|
|
|
var playlist = document.getElementById('playlist');
|
2019-05-06 14:48:33 +00:00
|
|
|
|
|
2022-05-06 01:46:59 +00:00
|
|
|
|
playlist.innerHTML = spinnerHTMLwithHR;
|
2019-05-06 14:48:33 +00:00
|
|
|
|
|
2022-04-20 10:04:44 +00:00
|
|
|
|
var plid_url;
|
2019-05-06 14:48:33 +00:00
|
|
|
|
if (plid.startsWith('RD')) {
|
2022-04-20 10:04:44 +00:00
|
|
|
|
plid_url = '/api/v1/mixes/' + plid +
|
2019-05-06 16:23:14 +00:00
|
|
|
|
'?continuation=' + video_data.id +
|
|
|
|
|
'&format=html&hl=' + video_data.preferences.locale;
|
2019-05-06 14:48:33 +00:00
|
|
|
|
} else {
|
2022-04-20 10:04:44 +00:00
|
|
|
|
plid_url = '/api/v1/playlists/' + plid +
|
2019-08-05 23:49:13 +00:00
|
|
|
|
'?index=' + video_data.index +
|
|
|
|
|
'&continuation=' + video_data.id +
|
2019-05-06 16:23:14 +00:00
|
|
|
|
'&format=html&hl=' + video_data.preferences.locale;
|
2019-05-06 14:48:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 01:46:59 +00:00
|
|
|
|
helpers.xhr('GET', plid_url, {retries: 5, entity_name: 'playlist'}, {
|
|
|
|
|
on200: function (response) {
|
|
|
|
|
playlist.innerHTML = response.playlistHtml;
|
|
|
|
|
|
|
|
|
|
if (!response.nextVideo) return;
|
|
|
|
|
|
|
|
|
|
var nextVideo = document.getElementById(response.nextVideo);
|
|
|
|
|
nextVideo.parentNode.parentNode.scrollTop = nextVideo.offsetTop;
|
|
|
|
|
|
|
|
|
|
player.on('ended', function () {
|
|
|
|
|
var url = new URL('https://example.com/watch?v=' + response.nextVideo);
|
|
|
|
|
|
|
|
|
|
url.searchParams.set('list', plid);
|
|
|
|
|
if (!plid.startsWith('RD'))
|
|
|
|
|
url.searchParams.set('index', response.index);
|
|
|
|
|
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
|
|
|
|
url.searchParams.set('autoplay', '1');
|
|
|
|
|
if (video_data.params.listen !== video_data.preferences.listen)
|
|
|
|
|
url.searchParams.set('listen', video_data.params.listen);
|
|
|
|
|
if (video_data.params.speed !== video_data.preferences.speed)
|
|
|
|
|
url.searchParams.set('speed', video_data.params.speed);
|
|
|
|
|
if (video_data.params.local !== video_data.preferences.local)
|
|
|
|
|
url.searchParams.set('local', video_data.params.local);
|
|
|
|
|
|
|
|
|
|
location.assign(url.pathname + url.search);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onNon200: function (xhr) {
|
|
|
|
|
playlist.innerHTML = '';
|
|
|
|
|
document.getElementById('continue').style.display = '';
|
|
|
|
|
},
|
|
|
|
|
onError: function (xhr) {
|
|
|
|
|
playlist.innerHTML = spinnerHTMLwithHR;
|
|
|
|
|
},
|
|
|
|
|
onTimeout: function (xhr) {
|
|
|
|
|
playlist.innerHTML = spinnerHTMLwithHR;
|
2019-05-06 14:48:33 +00:00
|
|
|
|
}
|
2022-05-06 01:46:59 +00:00
|
|
|
|
});
|
2019-05-06 14:48:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 01:46:59 +00:00
|
|
|
|
function get_reddit_comments() {
|
2022-04-20 10:23:24 +00:00
|
|
|
|
var comments = document.getElementById('comments');
|
2019-05-06 14:48:33 +00:00
|
|
|
|
|
|
|
|
|
var fallback = comments.innerHTML;
|
2022-05-06 01:46:59 +00:00
|
|
|
|
comments.innerHTML = spinnerHTML;
|
2019-05-06 14:48:33 +00:00
|
|
|
|
|
2019-05-06 16:23:14 +00:00
|
|
|
|
var url = '/api/v1/comments/' + video_data.id +
|
2019-05-06 14:48:33 +00:00
|
|
|
|
'?source=reddit&format=html' +
|
2019-05-06 16:23:14 +00:00
|
|
|
|
'&hl=' + video_data.preferences.locale;
|
2022-05-06 01:46:59 +00:00
|
|
|
|
|
|
|
|
|
var onNon200 = function (xhr) { comments.innerHTML = fallback; };
|
|
|
|
|
if (video_data.params.comments[1] === 'youtube')
|
|
|
|
|
onNon200 = function (xhr) {};
|
2022-06-05 17:54:48 +00:00
|
|
|
|
|
2022-05-06 01:46:59 +00:00
|
|
|
|
helpers.xhr('GET', url, {retries: 5, entity_name: ''}, {
|
|
|
|
|
on200: function (response) {
|
|
|
|
|
comments.innerHTML = ' \
|
|
|
|
|
<div> \
|
|
|
|
|
<h3> \
|
|
|
|
|
<a href="javascript:void(0)">[ − ]</a> \
|
|
|
|
|
{title} \
|
|
|
|
|
</h3> \
|
|
|
|
|
<p> \
|
2019-05-06 14:48:33 +00:00
|
|
|
|
<b> \
|
2022-05-06 01:46:59 +00:00
|
|
|
|
<a href="javascript:void(0)" data-comments="youtube"> \
|
|
|
|
|
{youtubeCommentsText} \
|
|
|
|
|
</a> \
|
2019-05-06 14:48:33 +00:00
|
|
|
|
</b> \
|
2022-05-06 01:46:59 +00:00
|
|
|
|
</p> \
|
|
|
|
|
<b> \
|
|
|
|
|
<a rel="noopener" target="_blank" href="https://reddit.com{permalink}">{redditPermalinkText}</a> \
|
|
|
|
|
</b> \
|
|
|
|
|
</div> \
|
|
|
|
|
<div>{contentHtml}</div> \
|
|
|
|
|
<hr>'.supplant({
|
|
|
|
|
title: response.title,
|
|
|
|
|
youtubeCommentsText: video_data.youtube_comments_text,
|
|
|
|
|
redditPermalinkText: video_data.reddit_permalink_text,
|
|
|
|
|
permalink: response.permalink,
|
|
|
|
|
contentHtml: response.contentHtml
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
comments.children[0].children[0].children[0].onclick = toggle_comments;
|
|
|
|
|
comments.children[0].children[1].children[0].onclick = swap_comments;
|
|
|
|
|
},
|
|
|
|
|
onNon200: onNon200, // declared above
|
|
|
|
|
});
|
2019-05-06 14:48:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 16:23:14 +00:00
|
|
|
|
if (video_data.play_next) {
|
2019-05-06 14:48:33 +00:00
|
|
|
|
player.on('ended', function () {
|
2019-05-06 16:23:14 +00:00
|
|
|
|
var url = new URL('https://example.com/watch?v=' + video_data.next_video);
|
2019-05-06 14:48:33 +00:00
|
|
|
|
|
2022-05-06 01:46:59 +00:00
|
|
|
|
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
2019-05-06 14:48:33 +00:00
|
|
|
|
url.searchParams.set('autoplay', '1');
|
2022-05-06 01:46:59 +00:00
|
|
|
|
if (video_data.params.listen !== video_data.preferences.listen)
|
2019-05-06 16:23:14 +00:00
|
|
|
|
url.searchParams.set('listen', video_data.params.listen);
|
2022-05-06 01:46:59 +00:00
|
|
|
|
if (video_data.params.speed !== video_data.preferences.speed)
|
2019-05-06 16:23:14 +00:00
|
|
|
|
url.searchParams.set('speed', video_data.params.speed);
|
2022-05-06 01:46:59 +00:00
|
|
|
|
if (video_data.params.local !== video_data.preferences.local)
|
2019-05-27 17:16:22 +00:00
|
|
|
|
url.searchParams.set('local', video_data.params.local);
|
2019-05-06 14:48:33 +00:00
|
|
|
|
url.searchParams.set('continue', '1');
|
2022-05-06 01:46:59 +00:00
|
|
|
|
|
2019-05-06 14:48:33 +00:00
|
|
|
|
location.assign(url.pathname + url.search);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 01:46:59 +00:00
|
|
|
|
addEventListener('load', function (e) {
|
|
|
|
|
if (video_data.plid)
|
2019-10-18 16:44:11 +00:00
|
|
|
|
get_playlist(video_data.plid);
|
2023-06-29 06:48:43 +00:00
|
|
|
|
if (video_data.compid)
|
|
|
|
|
get_compilation(video_data.compid);
|
2019-10-18 16:44:11 +00:00
|
|
|
|
if (video_data.params.comments[0] === 'youtube') {
|
|
|
|
|
get_youtube_comments();
|
|
|
|
|
} else if (video_data.params.comments[0] === 'reddit') {
|
|
|
|
|
get_reddit_comments();
|
|
|
|
|
} else if (video_data.params.comments[1] === 'youtube') {
|
|
|
|
|
get_youtube_comments();
|
|
|
|
|
} else if (video_data.params.comments[1] === 'reddit') {
|
|
|
|
|
get_reddit_comments();
|
|
|
|
|
} else {
|
2022-04-20 10:23:24 +00:00
|
|
|
|
var comments = document.getElementById('comments');
|
2019-10-18 16:44:11 +00:00
|
|
|
|
comments.innerHTML = '';
|
|
|
|
|
}
|
|
|
|
|
});
|