mirror of
https://github.com/iv-org/invidious.git
synced 2025-07-14 17:38:29 +00:00
more refactoring
This commit is contained in:
parent
88e80d50ad
commit
c365cd274e
@ -22,34 +22,25 @@ function toggle_comments(event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hide_youtube_replies(event) {
|
function toggle_youtube_replies(target, next_click_action) {
|
||||||
var target = event.target;
|
|
||||||
|
|
||||||
var sub_text = target.getAttribute('data-inner-text');
|
var sub_text = target.getAttribute('data-inner-text');
|
||||||
var inner_text = target.getAttribute('data-sub-text');
|
var inner_text = target.getAttribute('data-sub-text');
|
||||||
|
|
||||||
var body = target.parentNode.parentNode.children[1];
|
var body = target.parentNode.parentNode.children[1];
|
||||||
body.style.display = 'none';
|
body.style.display = next_click_action === show_youtube_replies ? 'none' : '';
|
||||||
|
|
||||||
target.textContent = sub_text;
|
target.textContent = sub_text;
|
||||||
target.onclick = show_youtube_replies;
|
target.onclick = next_click_action;
|
||||||
target.setAttribute('data-inner-text', inner_text);
|
target.setAttribute('data-inner-text', inner_text);
|
||||||
target.setAttribute('data-sub-text', sub_text);
|
target.setAttribute('data-sub-text', sub_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hide_youtube_replies(event) {
|
||||||
|
toggle_youtube_replies(event.target, show_youtube_replies);
|
||||||
|
}
|
||||||
|
|
||||||
function show_youtube_replies(event) {
|
function show_youtube_replies(event) {
|
||||||
var target = event.target;
|
toggle_youtube_replies(event.target, hide_youtube_replies);
|
||||||
|
|
||||||
var sub_text = target.getAttribute('data-inner-text');
|
|
||||||
var inner_text = target.getAttribute('data-sub-text');
|
|
||||||
|
|
||||||
var body = target.parentNode.parentNode.children[1];
|
|
||||||
body.style.display = '';
|
|
||||||
|
|
||||||
target.textContent = sub_text;
|
|
||||||
target.onclick = hide_youtube_replies;
|
|
||||||
target.setAttribute('data-inner-text', inner_text);
|
|
||||||
target.setAttribute('data-sub-text', sub_text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_youtube_comments() {
|
function get_youtube_comments() {
|
||||||
|
@ -1,34 +1,25 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var community_data = JSON.parse(document.getElementById('community_data').textContent);
|
var community_data = JSON.parse(document.getElementById('community_data').textContent);
|
||||||
|
|
||||||
function hide_youtube_replies(event) {
|
function toggle_youtube_replies(target, next_click_action) {
|
||||||
var target = event.target;
|
|
||||||
|
|
||||||
var sub_text = target.getAttribute('data-inner-text');
|
var sub_text = target.getAttribute('data-inner-text');
|
||||||
var inner_text = target.getAttribute('data-sub-text');
|
var inner_text = target.getAttribute('data-sub-text');
|
||||||
|
|
||||||
var body = target.parentNode.parentNode.children[1];
|
var body = target.parentNode.parentNode.children[1];
|
||||||
body.style.display = 'none';
|
body.style.display = next_click_action === show_youtube_replies ? 'none' : '';
|
||||||
|
|
||||||
target.innerHTML = sub_text;
|
target.innerHTML = sub_text;
|
||||||
target.onclick = show_youtube_replies;
|
target.onclick = next_click_action;
|
||||||
target.setAttribute('data-inner-text', inner_text);
|
target.setAttribute('data-inner-text', inner_text);
|
||||||
target.setAttribute('data-sub-text', sub_text);
|
target.setAttribute('data-sub-text', sub_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hide_youtube_replies(event) {
|
||||||
|
toggle_youtube_replies(event.target, show_youtube_replies);
|
||||||
|
}
|
||||||
|
|
||||||
function show_youtube_replies(event) {
|
function show_youtube_replies(event) {
|
||||||
var target = event.target;
|
toggle_youtube_replies(event.target, hide_youtube_replies);
|
||||||
|
|
||||||
var sub_text = target.getAttribute('data-inner-text');
|
|
||||||
var inner_text = target.getAttribute('data-sub-text');
|
|
||||||
|
|
||||||
var body = target.parentNode.parentNode.children[1];
|
|
||||||
body.style.display = '';
|
|
||||||
|
|
||||||
target.innerHTML = sub_text;
|
|
||||||
target.onclick = hide_youtube_replies;
|
|
||||||
target.setAttribute('data-inner-text', inner_text);
|
|
||||||
target.setAttribute('data-sub-text', sub_text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_youtube_replies(target, load_more) {
|
function get_youtube_replies(target, load_more) {
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var video_data = JSON.parse(document.getElementById('video_data').textContent);
|
var video_data = JSON.parse(document.getElementById('video_data').textContent);
|
||||||
|
|
||||||
|
function set_search_params() {
|
||||||
|
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
||||||
|
url.searchParams.set('autoplay', '1');
|
||||||
|
|
||||||
|
['listen', 'speed', 'local'].forEach(p => {
|
||||||
|
if (video_data.params[p] !== video_data.preferences[p])
|
||||||
|
url.searchParams.set(p, video_data.params[p]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function get_playlist(plid) {
|
function get_playlist(plid) {
|
||||||
var plid_url;
|
var plid_url;
|
||||||
if (plid.startsWith('RD')) {
|
if (plid.startsWith('RD')) {
|
||||||
@ -25,14 +35,7 @@ function get_playlist(plid) {
|
|||||||
url.searchParams.set('list', plid);
|
url.searchParams.set('list', plid);
|
||||||
if (!plid.startsWith('RD'))
|
if (!plid.startsWith('RD'))
|
||||||
url.searchParams.set('index', response.index);
|
url.searchParams.set('index', response.index);
|
||||||
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
set_search_params();
|
||||||
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);
|
location.assign(url.pathname + url.search);
|
||||||
});
|
});
|
||||||
@ -47,14 +50,7 @@ addEventListener('load', function (e) {
|
|||||||
player.on('ended', function () {
|
player.on('ended', function () {
|
||||||
var url = new URL('https://example.com/embed/' + video_data.video_series.shift());
|
var url = new URL('https://example.com/embed/' + video_data.video_series.shift());
|
||||||
|
|
||||||
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
set_search_params();
|
||||||
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);
|
|
||||||
if (video_data.video_series.length !== 0)
|
if (video_data.video_series.length !== 0)
|
||||||
url.searchParams.set('playlist', video_data.video_series.join(','));
|
url.searchParams.set('playlist', video_data.video_series.join(','));
|
||||||
|
|
||||||
|
@ -26,17 +26,20 @@ if (continue_button) {
|
|||||||
continue_button.onclick = continue_autoplay;
|
continue_button.onclick = continue_autoplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function set_search_params() {
|
||||||
|
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
||||||
|
url.searchParams.set('autoplay', '1');
|
||||||
|
|
||||||
|
['listen', 'speed', 'local'].forEach(p => {
|
||||||
|
if (video_data.params[p] !== video_data.preferences[p])
|
||||||
|
url.searchParams.set(p, video_data.params[p]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function next_video() {
|
function next_video() {
|
||||||
var url = new URL('https://example.com/watch?v=' + video_data.next_video);
|
var url = new URL('https://example.com/watch?v=' + video_data.next_video);
|
||||||
|
|
||||||
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
set_search_params();
|
||||||
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);
|
|
||||||
url.searchParams.set('continue', '1');
|
url.searchParams.set('continue', '1');
|
||||||
|
|
||||||
location.assign(url.pathname + url.search);
|
location.assign(url.pathname + url.search);
|
||||||
@ -82,14 +85,7 @@ function get_playlist(plid) {
|
|||||||
url.searchParams.set('list', plid);
|
url.searchParams.set('list', plid);
|
||||||
if (!plid.startsWith('RD'))
|
if (!plid.startsWith('RD'))
|
||||||
url.searchParams.set('index', response.index);
|
url.searchParams.set('index', response.index);
|
||||||
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
set_search_params();
|
||||||
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);
|
location.assign(url.pathname + url.search);
|
||||||
});
|
});
|
||||||
@ -117,10 +113,6 @@ function get_reddit_comments() {
|
|||||||
'?source=reddit&format=html' +
|
'?source=reddit&format=html' +
|
||||||
'&hl=' + video_data.preferences.locale;
|
'&hl=' + video_data.preferences.locale;
|
||||||
|
|
||||||
var onNon200 = function (xhr) { comments.innerHTML = fallback; };
|
|
||||||
if (video_data.params.comments[1] === 'youtube')
|
|
||||||
onNon200 = function (xhr) {};
|
|
||||||
|
|
||||||
helpers.xhr('GET', url, {retries: 5, entity_name: ''}, {
|
helpers.xhr('GET', url, {retries: 5, entity_name: ''}, {
|
||||||
on200: function (response) {
|
on200: function (response) {
|
||||||
comments.innerHTML = ' \
|
comments.innerHTML = ' \
|
||||||
@ -152,7 +144,9 @@ function get_reddit_comments() {
|
|||||||
comments.children[0].children[0].children[0].onclick = toggle_comments;
|
comments.children[0].children[0].children[0].onclick = toggle_comments;
|
||||||
comments.children[0].children[1].children[0].onclick = swap_comments;
|
comments.children[0].children[1].children[0].onclick = swap_comments;
|
||||||
},
|
},
|
||||||
onNon200: onNon200, // declared above
|
onNon200: video_data.params.comments[1] === 'youtube'
|
||||||
|
? function (xhr) {}
|
||||||
|
: function (xhr) { comments.innerHTML = fallback; }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,14 +154,7 @@ if (video_data.play_next) {
|
|||||||
player.on('ended', function () {
|
player.on('ended', function () {
|
||||||
var url = new URL('https://example.com/watch?v=' + video_data.next_video);
|
var url = new URL('https://example.com/watch?v=' + video_data.next_video);
|
||||||
|
|
||||||
if (video_data.params.autoplay || video_data.params.continue_autoplay)
|
set_search_params();
|
||||||
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);
|
|
||||||
url.searchParams.set('continue', '1');
|
url.searchParams.set('continue', '1');
|
||||||
|
|
||||||
location.assign(url.pathname + url.search);
|
location.assign(url.pathname + url.search);
|
||||||
@ -178,13 +165,14 @@ addEventListener('load', function (e) {
|
|||||||
if (video_data.plid)
|
if (video_data.plid)
|
||||||
get_playlist(video_data.plid);
|
get_playlist(video_data.plid);
|
||||||
|
|
||||||
if (video_data.params.comments[0] === 'youtube') {
|
const c = video_data.params.comments;
|
||||||
|
if (c[0] === 'youtube') {
|
||||||
get_youtube_comments();
|
get_youtube_comments();
|
||||||
} else if (video_data.params.comments[0] === 'reddit') {
|
} else if (c[0] === 'reddit') {
|
||||||
get_reddit_comments();
|
get_reddit_comments();
|
||||||
} else if (video_data.params.comments[1] === 'youtube') {
|
} else if (c[1] === 'youtube') {
|
||||||
get_youtube_comments();
|
get_youtube_comments();
|
||||||
} else if (video_data.params.comments[1] === 'reddit') {
|
} else if (c[1] === 'reddit') {
|
||||||
get_reddit_comments();
|
get_reddit_comments();
|
||||||
} else {
|
} else {
|
||||||
var comments = document.getElementById('comments');
|
var comments = document.getElementById('comments');
|
||||||
|
Loading…
Reference in New Issue
Block a user