blankie 2024-03-14 09:39:22 +11:00
parent 909dc69dc0
commit cbebfa5995
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 10 additions and 3 deletions

View File

@ -2,7 +2,7 @@
// @name Tildes with "Newest reply"
// @namespace blankie-scripts
// @match https://tildes.net/*
// @version 1.0.1
// @version 1.0.2
// @author blankie
// @description A userscript that adds a "newest reply" to topics on Tildes
// @inject-into content
@ -23,12 +23,19 @@ function commentSortKey(li) {
return new Date(li.querySelector(".comment-header .comment-posted-time").dateTime);
}
function sortCommentsByNewestReply(ol = null) {
function sortCommentsByNewestReply(ol = null, sortedCommentTrees = null) {
ol = ol || document.querySelector("#comments");
sortedCommentTrees = sortedCommentTrees || new WeakSet();
let comments = [];
for (let li of ol.children) {
sortCommentsByNewestReply(li.querySelector(".comment-tree"));
let commentTree = li.querySelector(".comment-tree");
if (!commentTree || sortedCommentTrees.has(commentTree)) {
continue;
}
sortedCommentTrees.add(commentTree);
sortCommentsByNewestReply(commentTree, sortedCommentTrees);
comments.push(li);
}