From cbebfa5995bf7c6c0bdb3e95ba91809c095aefae Mon Sep 17 00:00:00 2001 From: blankie Date: Thu, 14 Mar 2024 09:39:22 +1100 Subject: [PATCH] Update Tildes with "Newest reply" to 1.0.2 - Fix hang on https://tildes.net/~lgbt/1evw/children_to_no_longer_be_prescribed_puberty_blockers_nhs_england_confirms?b_comment_order=newest_reply --- Tildes with -Newest reply-.user.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Tildes with -Newest reply-.user.js b/Tildes with -Newest reply-.user.js index f00d7b3..2819975 100644 --- a/Tildes with -Newest reply-.user.js +++ b/Tildes with -Newest reply-.user.js @@ -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); }