diff --git a/index.js b/index.js index 74c6c49..3c27e27 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,6 @@ pageMod.PageMod({ notDataUrl("lib/modules/infinite_scrolling.js"), notDataUrl("lib/modules/accurate_domain_names.js"), notDataUrl("lib/modules/mark_as_read.js"), - notDataUrl("lib/modules/fold_comments.js"), notDataUrl("lib/modules/sticky_header.js"), notDataUrl("lib/modules/user_tooltips.js") ], diff --git a/lib/defaults.json b/lib/defaults.json index 0a82322..f3dc04a 100644 --- a/lib/defaults.json +++ b/lib/defaults.json @@ -9,7 +9,6 @@ "open_links_in_new_tabs": false, "highlight_links_when_returning": true, "accurate_domain_names": true, - "fold_comments": true, "mark_as_read": false, "sticky_header": false, "user_tooltips": false, @@ -37,7 +36,6 @@ "Accurate domain names shows you more precisely where a link takes (e.g., github.com becomes gist.github.com)!", "You can try High contrast if you have issues reading some of the text on the site.", "Highlight links when returning will help you find which link you came from when coming back to Hacker News!", - "Fold comments adds a button to comments that lets you expand or collapse them as you read!", "Mark as read allows you to mark links as visited, or to mark an entire page of links as read.", "Use Sticky header if you'd like to make the header follow you through the page.", "Gray visited links could make it easier for you to distinguish the links you haven't clicked on yet.", diff --git a/lib/modules/fold_comments.js b/lib/modules/fold_comments.js deleted file mode 100644 index cd179ea..0000000 --- a/lib/modules/fold_comments.js +++ /dev/null @@ -1,72 +0,0 @@ -HNSpecial.settings.registerModule("fold_comments", function () { - var baseWidth = 40; - - if (_.isCommentPage() || location.pathname.match(/^\/(item|threads)/)) { - _.toArray(document.getElementsByClassName("default")).forEach(function (comment) { - var row = comment.parentElement.parentElement.parentElement.parentElement.parentElement; // Least horrible way to get to the comment row - - // Skip this row if we're on a comment permalink page and it's the comment at the top - if (row.nextElementSibling && row.nextElementSibling.getElementsByClassName("yclinks").length) return; - - var comhead = comment.getElementsByClassName("comhead")[0]; - comhead.appendChild(document.createTextNode(" | ")); - - var button = _.createElement("button", { - content: "[ - ]", - classes: ["hnspecial-fold-comment-button"] - }); - comhead.appendChild(button); - - button.addEventListener("click", function () { - var folded = comment.classList.contains("hnspecial-folded-comment"); - var method = folded ? "remove" : "add"; - - // Fold/unfold the current comment - comment.classList[method]("hnspecial-folded-comment"); - button.innerHTML = folded ? "[ - ]" : "[ + ]"; - - // Depth of the current comment - var baseDepth = getCommentDepth(row); - - var current = row; - - // The comments are not organised in a tree so we have to cycle through - // each row and find the nesting manually, then also skip appropriately - // if some of the comments below the one we're folding are already folded - var foldedDepth = null; // Depth of the topmost folded comment in the tree we're folding - - // Fold nested comments (if present) - while (current = current.nextElementSibling) { - var depth = getCommentDepth(current); - - if (depth <= baseDepth) { - break; - } - - // Check if we need to skip the comment because it's under a folded one - if (foldedDepth !== null) { - if (depth > foldedDepth) { - continue; - } else { - // We're out of the comments nested under the hidden one so we can stop skipping - foldedDepth = null; - } - } - - // If the current comment is folded, set foldedDepth to avoid touching the nested ones - if (current.getElementsByClassName("hnspecial-folded-comment").length) { - foldedDepth = depth; - } - - // Fold/unfold the current comment - current.classList[method]("hnspecial-folded-row"); - } - }); - }); - } - - function getCommentDepth(comment) { - var spacer = comment.getElementsByTagName("img")[0]; - return parseInt(spacer.getAttribute("width"), 10) / baseWidth; - } -}); diff --git a/manifest.json b/manifest.json index 6960f0f..8d244e3 100644 --- a/manifest.json +++ b/manifest.json @@ -36,7 +36,6 @@ "lib/modules/infinite_scrolling.js", "lib/modules/accurate_domain_names.js", "lib/modules/mark_as_read.js", - "lib/modules/fold_comments.js", "lib/modules/sticky_header.js", "lib/modules/user_tooltips.js", "lib/modules/hide_downvote.js"