Fix whitespace being stripped from the comment before filtering.

This makes it possible to filter whitespace spam.
This commit is contained in:
ccd0 2015-04-24 01:02:57 -07:00
parent c9209dd672
commit b83c2c9811
3 changed files with 23 additions and 17 deletions

View File

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

View File

@ -106,22 +106,28 @@ class Post
# 'Comment too long'...
# EXIF data. (/p/)
# Rolls. (/tg/)
# Marquees. (/pol/)
# Fortunes. (/s4s/)
bq = @nodes.comment.cloneNode true
for node in $$ '.abbr + br, .exif, b, .fortune', bq
$.rm node
if abbr = $ '.abbr', bq
$.rm abbr
@info.comment = @nodesToText bq
if abbr
@info.comment = @info.comment.replace /\n\n$/, ''
# Hide spoilers.
# Remove:
# Preceding and following new lines.
# Trailing spaces.
bq = @nodes.comment.cloneNode true
for node in $$ '.abbr, .exif, b, marquee', bq
$.rm node
@info.comment = @nodesToText bq
# Get the comment's text with spoilers hidden.
spoilers = $$ 's', bq
@info.commentSpoilered = if spoilers.length
for node in spoilers
$.replace node, $.tn '[spoiler]'
@nodesToText bq
else
@info.comment
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, ''
nodesToText: (bq) ->
text = ""
@ -129,7 +135,7 @@ class Post
i = 0
while node = nodes.snapshotItem i++
text += node.data or '\n'
text.trim().replace /\s+$/gm, ''
text
parseQuotes: ->
@quotes = []

View File

@ -128,7 +128,7 @@ Unread =
openNotification: (post) ->
return unless Header.areNotificationsEnabled
notif = new Notification "#{post.info.nameBlock} replied to you",
body: post.info[if Conf['Remove Spoilers'] or Conf['Reveal Spoilers'] then 'comment' else 'commentSpoilered']
body: post.info.commentDisplay
icon: Favicon.logo
notif.onclick = ->
Header.scrollToIfNeeded post.nodes.root, true