2022-04-20 14:08:24 +05:30
|
|
|
'use strict';
|
2022-04-20 16:10:30 +05:30
|
|
|
var community_data = JSON.parse(document.getElementById('community_data').textContent);
|
2020-03-16 03:16:08 +05:30
|
|
|
|
2023-10-23 06:21:14 +05:30
|
|
|
// 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
|
|
|
|
2023-10-23 06:21:14 +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
|
|
|
|
2023-10-23 06:21:14 +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;
|
|
|
|
|
2022-05-06 07:16:59 +05:30
|
|
|
helpers.xhr('GET', url, {}, {
|
|
|
|
on200: function (response) {
|
2023-10-23 06:21:14 +05:30
|
|
|
body = body.parentNode.parentNode;
|
|
|
|
body.removeChild(body.lastElementChild);
|
|
|
|
body.insertAdjacentHTML('beforeend', updateReplyLinkHtml(response.contentHtml));
|
2022-05-06 07:16:59 +05:30
|
|
|
},
|
|
|
|
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
|
|
|
}
|
2022-05-06 07:16:59 +05:30
|
|
|
});
|
2019-07-09 20:01:04 +05:30
|
|
|
}
|