Include rolls and fortunes in filterable text but continue removing them from notifications and thread excerpts.

This commit is contained in:
ccd0 2016-10-09 17:29:00 -07:00
parent e7eb5fd2ab
commit 6484f461d0
4 changed files with 35 additions and 23 deletions

View File

@ -83,8 +83,6 @@ Build =
html = html
.replace(/<br\b[^<]*>/gi, '\n')
.replace(/\n\n<span\b[^<]* class="abbr"[^]*$/i, '') # EXIF data (/p/)
.replace(/^<b\b[^<]*>Rolled [^<]*<\/b>/i, '') # Rolls (/tg/)
.replace(/<span\b[^<]* class="fortune"[^]*$/i, '') # Fortunes (/s4s/)
.replace(/<[^>]*>/g, '')
Build.unescape html
@ -93,6 +91,9 @@ Build =
unless Conf['Remove Spoilers'] or Conf['Reveal Spoilers']
while (html2 = html.replace /<s>(?:(?!<\/?s>).)*<\/s>/g, '[spoiler]') isnt html
html = html2
html = html
.replace(/^<b\b[^<]*>Rolled [^<]*<\/b>/i, '') # Rolls (/tg/, /qst/)
.replace(/<span\b[^<]* class="fortune"[^]*$/i, '') # Fortunes (/s4s/)
# Remove preceding and following new lines, trailing spaces.
Build.parseComment(html).trim().replace(/\s+$/gm, '')

View File

@ -3,7 +3,7 @@ Get =
{OP} = thread
excerpt = ("/#{thread.board}/ - ") + (
OP.info.subject?.trim() or
OP.info.commentDisplay.replace(/\n+/g, ' // ') or
OP.commentDisplay().replace(/\n+/g, ' // ') or
OP.file?.name or
"No.#{OP}")
return "#{excerpt[...70]}..." if excerpt.length > 73

View File

@ -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

View File

@ -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