mirror of
https://github.com/iv-org/invidious.git
synced 2025-01-10 19:40:35 +05:30
42 lines
1.6 KiB
JavaScript
42 lines
1.6 KiB
JavaScript
'use strict';
|
|
var community_data = JSON.parse(document.getElementById('community_data').textContent);
|
|
|
|
// first page of community posts are loaded without javascript so we need to update the Load more button
|
|
var initialLoadMore = document.querySelector('a[data-onclick="get_youtube_replies"]');
|
|
initialLoadMore.setAttribute('href', 'javascript:void(0);');
|
|
initialLoadMore.removeAttribute('target');
|
|
|
|
function updateReplyLinkHtml(contentHtml) {
|
|
return contentHtml.replace(/target="_blank" href="\/comment_viewer\?[^"]*"/g, 'href="javascript:void(0)"');
|
|
};
|
|
|
|
function get_youtube_replies(target) {
|
|
var continuation = target.getAttribute('data-continuation');
|
|
|
|
var body = target.parentNode.parentNode;
|
|
var fallback = body.innerHTML;
|
|
body.innerHTML =
|
|
'<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3>';
|
|
|
|
var url = '/api/v1/channels/comments/' + community_data.ucid +
|
|
'?format=html' +
|
|
'&hl=' + community_data.preferences.locale +
|
|
'&thin_mode=' + community_data.preferences.thin_mode +
|
|
'&continuation=' + continuation;
|
|
|
|
helpers.xhr('GET', url, {}, {
|
|
on200: function (response) {
|
|
body = body.parentNode.parentNode;
|
|
body.removeChild(body.lastElementChild);
|
|
body.insertAdjacentHTML('beforeend', updateReplyLinkHtml(response.contentHtml));
|
|
},
|
|
onNon200: function (xhr) {
|
|
body.innerHTML = fallback;
|
|
},
|
|
onTimeout: function (xhr) {
|
|
console.warn('Pulling comments failed');
|
|
body.innerHTML = fallback;
|
|
}
|
|
});
|
|
}
|