From 6484f461d057d92391ee2fc867fb930efc1b5ee7 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 9 Oct 2016 17:29:00 -0700 Subject: [PATCH] Include rolls and fortunes in filterable text but continue removing them from notifications and thread excerpts. --- src/General/Build.coffee | 5 ++-- src/General/Get.coffee | 2 +- src/Monitoring/Unread.coffee | 2 +- src/classes/Post.coffee | 49 ++++++++++++++++++++++-------------- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/General/Build.coffee b/src/General/Build.coffee index bf7dbb308..0a1c6e123 100644 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -83,8 +83,6 @@ Build = html = html .replace(//gi, '\n') .replace(/\n\nRolled [^<]*<\/b>/i, '') # Rolls (/tg/) - .replace(/]*>/g, '') Build.unescape html @@ -93,6 +91,9 @@ Build = unless Conf['Remove Spoilers'] or Conf['Reveal Spoilers'] while (html2 = html.replace /(?:(?!<\/?s>).)*<\/s>/g, '[spoiler]') isnt html html = html2 + html = html + .replace(/^Rolled [^<]*<\/b>/i, '') # Rolls (/tg/, /qst/) + .replace(/ 73 diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index d2b801cc8..f7784e592 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -132,7 +132,7 @@ Unread = openNotification: (post) -> return unless Header.areNotificationsEnabled notif = new Notification "#{post.info.nameBlock} replied to you", - body: post.info.commentDisplay + body: post.commentDisplay() icon: Favicon.logo notif.onclick = -> Header.scrollToIfNeeded post.nodes.root, true diff --git a/src/classes/Post.coffee b/src/classes/Post.coffee index 50474357d..ebf66201e 100644 --- a/src/classes/Post.coffee +++ b/src/classes/Post.coffee @@ -107,29 +107,22 @@ class Post # Remove: # 'Comment too long'... # EXIF data. (/p/) - # Rolls. (/tg/) - # Fortunes. (/s4s/) - bq = @nodes.comment.cloneNode true - for node in $$ '.abbr + br, .exif, b, .fortune', bq - $.rm node - if abbr = $ '.abbr', bq - $.rm abbr + @nodes.commentClean = bq = @nodes.comment.cloneNode true + @cleanComment bq @info.comment = @nodesToText bq - if abbr - @info.comment = @info.comment.replace /\n\n$/, '' - # Hide spoilers. - # Remove: + commentDisplay: -> + # Get the comment's text for display purposes (e.g. notifications, excerpts). + # In addition to what's done in generating `@info.comment`, remove: + # Spoilers. (filter to '[spoiler]') + # Rolls. (/tg/, /qst/) + # Fortunes. (/s4s/) # Preceding and following new lines. # Trailing spaces. - commentDisplay = @info.comment - unless Conf['Remove Spoilers'] or Conf['Reveal Spoilers'] - spoilers = $$ 's', bq - if spoilers.length - for node in spoilers - $.replace node, $.tn '[spoiler]' - commentDisplay = @nodesToText bq - @info.commentDisplay = commentDisplay.trim().replace /\s+$/gm, '' + bq = @nodes.commentClean.cloneNode true + @cleanSpoilers bq unless Conf['Remove Spoilers'] or Conf['Reveal Spoilers'] + @cleanCommentDisplay bq + @nodesToText(bq).trim().replace(/\s+$/gm, '') nodesToText: (bq) -> text = "" @@ -139,6 +132,24 @@ class Post text += node.data or '\n' text + cleanComment: (bq) -> + if (abbr = $ '.abbr', bq) # 'Comment too long' or 'EXIF data available' + for node in $$ '.abbr + br, .exif', bq + $.rm node + for i in [0...2] + $.rm br if (br = abbr.previousSibling) and br.nodeName is 'BR' + $.rm abbr + + cleanSpoilers: (bq) -> + spoilers = $$ 's', bq + for node in spoilers + $.replace node, $.tn '[spoiler]' + return + + cleanCommentDisplay: (bq) -> + $.rm b if (b = $ 'b', bq) and /^Rolled /.test(b.textContent) + $.rm $('.fortune', bq) + parseQuotes: -> @quotes = [] # XXX https://github.com/4chan/4chan-JS/issues/77