+ loading more than the first page of comments
parent
9e4d64defe
commit
6da0b9f673
|
@ -24,7 +24,7 @@ comments="$(curl -s 'https://www.youtube.com/youtubei/v1/next?key=AIzaSyAO_FJ2Sl
|
|||
|
||||
|
||||
jq -r 'select(.commentsHeaderRenderer) | "<h3>(whole \(.commentsHeaderRenderer.countText.runs[0].text) of them)</h3>"' <<< "$comments" | head -1
|
||||
jq -r 'if (.commentThreadRenderer != null) then
|
||||
jq -r '(if (.commentThreadRenderer != null) then
|
||||
.commentThreadRenderer | select(.comment.commentRenderer.authorText.simpleText != null)
|
||||
else
|
||||
.commentRenderer
|
||||
|
@ -38,6 +38,13 @@ comments="$(curl -s 'https://www.youtube.com/youtubei/v1/next?key=AIzaSyAO_FJ2Sl
|
|||
(.contentText.runs[] | if .bold == true then "<b>\(.text)</b>" else .text end),
|
||||
(select(.voteCount.simpleText != null) | "<br><small>\(.voteCount.simpleText) liked</small>")
|
||||
),
|
||||
(select(.replies.commentRepliesRenderer) | "<div class='"'"'show-more'"'"' data-uwu='"'"'\(.replies.commentRepliesRenderer.contents[0].continuationItemRenderer.continuationEndpoint.continuationCommand.token)'"'"'>Show replies</div>")
|
||||
(select(.replies.commentRepliesRenderer) | "<div class='"'"'show-more'"'"' data-fun='"'"'replies'"'"' data-uwu='"'"'\(.replies.commentRepliesRenderer.contents[0].continuationItemRenderer.continuationEndpoint.continuationCommand.token)'"'"'>Show replies</div>"))
|
||||
' <<< "$comments" | sed -E 's/^$/<br>/g'
|
||||
|
||||
echo "</pre></div>"
|
||||
|
||||
jq -r '
|
||||
if (.continuationItemRenderer.continuationEndpoint) then
|
||||
"<div class='"'"'show-more'"'"' data-fun='"'"'more'"'"' data-uwu='"'"'\(.continuationItemRenderer.continuationEndpoint.continuationCommand.token)'"'"'>Load more...</div>"
|
||||
else
|
||||
"<div class='"'"'show-more'"'"' data-fun='"'"'replies-more'"'"' data-uwu='"'"'\(.continuationItemRenderer.button.buttonRenderer.command.continuationCommand.token)'"'"'>More replies...</div>"
|
||||
end' <<< "$comments" | tail -1
|
||||
|
|
|
@ -9,10 +9,13 @@ pre {
|
|||
margin-top: 5px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.comment-thread, .show-more {
|
||||
.comment-thread, {
|
||||
margin-left: 16px;
|
||||
}
|
||||
|
||||
.show-more {
|
||||
cursor: pointer;
|
||||
color: #3d3;
|
||||
}
|
||||
.hide-cursor {
|
||||
cursor: none;
|
||||
}
|
||||
|
|
|
@ -1,43 +1,42 @@
|
|||
window.addEventListener("load", () => {
|
||||
const comments = document.querySelector(".comments");
|
||||
const id = new URLSearchParams(document.location.search).get("v");
|
||||
const comments = document.querySelector(".comments");
|
||||
const id = new URLSearchParams(document.location.search).get("v");
|
||||
|
||||
function showMore(e) {
|
||||
let a = e.target.cloneNode(true);
|
||||
a.classList.remove("show-more");
|
||||
a.classList.add("comment-thread");
|
||||
e.target.replaceWith(a);
|
||||
fetchComments(a, a.dataset.uwu);
|
||||
}
|
||||
|
||||
function fetchComments(div, cont) {
|
||||
div.innerText = "Loading...";
|
||||
if(!cont) {
|
||||
url = "/comments.shs?v=" + id;
|
||||
} else {
|
||||
url = "/comments.shs?cont=" + cont;
|
||||
function showMore(e) {
|
||||
if (e.target.classList.contains("show-more")) {
|
||||
e.target.classList.remove("show-more");
|
||||
if(e.target.dataset.fun == "replies") {
|
||||
e.target.classList.add("comment-thread");
|
||||
}
|
||||
fetch(url).then(
|
||||
res => {
|
||||
if (res.status !== 200) {
|
||||
throw new Error('HTTP Error ' + res.status);
|
||||
}
|
||||
return res.text();
|
||||
}
|
||||
).then(
|
||||
res => {
|
||||
div.innerHTML = res;
|
||||
if(!cont) {
|
||||
let show_more = document.querySelectorAll(".show-more");
|
||||
show_more.forEach((elem) => {
|
||||
elem.addEventListener("click", (e) => showMore(e));
|
||||
});
|
||||
}
|
||||
}
|
||||
).catch(
|
||||
err => div.innerText = 'Error during fetching comments: ' + err.message
|
||||
)
|
||||
fetchComments(e.target, e.target.dataset.uwu);
|
||||
}
|
||||
}
|
||||
|
||||
function fetchComments(div, cont) {
|
||||
div.innerText = "Loading...";
|
||||
if(!cont) {
|
||||
url = "/comments.shs?v=" + id;
|
||||
} else {
|
||||
url = "/comments.shs?cont=" + cont;
|
||||
}
|
||||
fetch(url).then(
|
||||
res => {
|
||||
if (res.status !== 200) {
|
||||
throw new Error('HTTP Error ' + res.status);
|
||||
}
|
||||
return res.text();
|
||||
}
|
||||
).then(
|
||||
res => {
|
||||
div.innerHTML = res;
|
||||
}
|
||||
).catch(
|
||||
err => div.innerText = 'Error during fetching comments: ' + err.message
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
window.addEventListener("load", () => {
|
||||
fetchComments(comments);
|
||||
})
|
||||
|
||||
window.addEventListener("click", (e) => showMore(e));
|
||||
|
|
Loading…
Reference in New Issue