+ loading more than the first page of comments
This commit is contained in:
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 '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)
|
.commentThreadRenderer | select(.comment.commentRenderer.authorText.simpleText != null)
|
||||||
else
|
else
|
||||||
.commentRenderer
|
.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),
|
(.contentText.runs[] | if .bold == true then "<b>\(.text)</b>" else .text end),
|
||||||
(select(.voteCount.simpleText != null) | "<br><small>\(.voteCount.simpleText) liked</small>")
|
(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'
|
' <<< "$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-top: 5px;
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
.comment-thread, .show-more {
|
.comment-thread, {
|
||||||
margin-left: 16px;
|
margin-left: 16px;
|
||||||
}
|
}
|
||||||
|
.show-more {
|
||||||
|
cursor: pointer;
|
||||||
|
color: #3d3;
|
||||||
|
}
|
||||||
.hide-cursor {
|
.hide-cursor {
|
||||||
cursor: none;
|
cursor: none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +1,42 @@
|
||||||
window.addEventListener("load", () => {
|
const comments = document.querySelector(".comments");
|
||||||
const comments = document.querySelector(".comments");
|
const id = new URLSearchParams(document.location.search).get("v");
|
||||||
const id = new URLSearchParams(document.location.search).get("v");
|
|
||||||
|
|
||||||
function showMore(e) {
|
function showMore(e) {
|
||||||
let a = e.target.cloneNode(true);
|
if (e.target.classList.contains("show-more")) {
|
||||||
a.classList.remove("show-more");
|
e.target.classList.remove("show-more");
|
||||||
a.classList.add("comment-thread");
|
if(e.target.dataset.fun == "replies") {
|
||||||
e.target.replaceWith(a);
|
e.target.classList.add("comment-thread");
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
fetch(url).then(
|
fetchComments(e.target, e.target.dataset.uwu);
|
||||||
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
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
fetchComments(comments);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
window.addEventListener("click", (e) => showMore(e));
|
||||||
|
|
Loading…
Reference in a new issue