From dd2320621dc1f49475dbdd3c562e7f019ae2f465 Mon Sep 17 00:00:00 2001 From: Jesper Wrang Date: Sun, 10 Sep 2017 23:26:35 +0200 Subject: [PATCH] Comments with body "[removed]" but still displayed are now seen as removed --- static/script.js | 41 +++++++++++++++++++--------------------- templates/frontpage.html | 3 +-- templates/header.html | 4 ++-- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/static/script.js b/static/script.js index 76c47cf..30289b2 100644 --- a/static/script.js +++ b/static/script.js @@ -35,7 +35,9 @@ const redditInit = { loadPage() async function loadPage() { + loadingImage.src = loadingImageSrc + loadingImage.style.display = "block" setLoadingText("Loading thread...") // Get thread from reddit and all comment IDs (inc. removed ones) from pushshift @@ -139,6 +141,15 @@ function extractMorechildrenIDs(comments) { async function getRemovedComments(allCommentIDs) { const idsDiff = allCommentIDs.filter(x => !commentIDs.includes(x)) + + commentIDs.forEach(id => { + if(commentLookup.has(id)) { + if(commentLookup.get(id).body === "[removed]") { + idsDiff.push(id) + } + } + }) + generateCommentInfo(idsDiff.length) console.log("All ids :", allCommentIDs) console.log("Comments ids (dup): ", commentIDs) @@ -200,7 +211,7 @@ async function getCommentsToGenerate(commentsToLookup) { if(commentsToFetch.length !== 0) { //await - console.log("fuck it") + console.error("fuck it, ill fix it later") } if(newCommentsToLookup.length !== 0) { @@ -272,31 +283,17 @@ function generateThread(data) { mainDiv.appendChild(threadDiv) } function createComment(comment) { - /*const comment_div = document.createElement("div") - comment_div.id = comment.id - comment_div.className = "comment comment-" + (comment.hasOwnProperty("removed") ? "removed" : (comment.depth % 2 == 0 ? "even" : "odd")); - comment_div.innerHTML = ` -
- [–] - ${comment.author} - ${pretty_score(comment.score)} point${(comment.score == 1) ? '': 's'} - ${pretty_date(comment.created_utc) } -
-
${markdown.render(comment.body)}
- - ` - return comment_div*/ + const isRemoved = comment.hasOwnProperty("removed") + return generateHTML(` -
+
[–] ${comment.author} ${prettyScore(comment.score)} point${(comment.score == 1) ? '': 's'} ${prettyDate(comment.created_utc) }
-
${markdown.render(comment.body)}
+
${comment.body === "[removed]" && isRemoved ? "

[likely removed by automoderator]

" : markdown.render(comment.body)}
@@ -317,7 +314,7 @@ function generateCommentInfo(removedCommentsAmount) { // Works for everything except iframes/script-tags, use "old fashion"-way in those cases (createElement etc...) function generateHTML(html) { - return htmlParser.parseFromString(html, "text/html").documentElement + return htmlParser.parseFromString(html, "text/html").body.firstChild } // "<" => "<" @@ -390,8 +387,8 @@ function prettyDate(createdUTC) { if(secondDiff < 86400) return Math.floor(secondDiff / 3600) + " hours ago" } - if(dayDiff == 1) - return "Yesterday" + //if(dayDiff == 1) + // return "Yesterday" if(dayDiff < 7) return dayDiff + " days ago" if(dayDiff < 31) diff --git a/templates/frontpage.html b/templates/frontpage.html index c799c5e..3d9b674 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -18,8 +18,7 @@
  • Collapsing comments
  • Get removed selftext of thread
  • -
  • Get "continue this thread"-comments to work
  • -
  • Show content of thread if image or video, also display thumbnail
  • +
  • Get nested "continue this thread"-comments to work

Acknowledgement

diff --git a/templates/header.html b/templates/header.html index 7be3867..d56abfe 100644 --- a/templates/header.html +++ b/templates/header.html @@ -11,8 +11,8 @@

\ No newline at end of file