invidious/assets/js/community.js

42 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-04-20 14:08:24 +05:30
'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');
2019-07-09 20:01:04 +05:30
function updateReplyLinkHtml(contentHtml) {
return contentHtml.replace(/target="_blank" href="\/comment_viewer\?[^"]*"/g, 'href="javascript:void(0)"');
};
2019-07-09 20:01:04 +05:30
function get_youtube_replies(target) {
2019-07-09 20:01:04 +05:30
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>';
2022-06-05 23:24:48 +05:30
2019-07-09 20:01:04 +05:30
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;
2019-07-09 20:01:04 +05:30
}
});
2019-07-09 20:01:04 +05:30
}