Quote markers.

This commit is contained in:
Mayhem 2014-02-08 18:05:33 +01:00
parent a072d67a8a
commit f6f1126130
11 changed files with 77 additions and 98 deletions

View File

@ -1,3 +1,8 @@
- New setting: `Quote Markers`, enabled by default
- This merges `Mark Quotes of You`, `Mark OP Quotes` and `Mark Cross-thread Quotes` into one feature.
- Backlinks now also get these markers.
- Multiple markers are now more compact, for example `>>123 (You/OP)` instead of `>>123 (You) (OP)`.
### 3.16.5 - *2014-02-07* ### 3.16.5 - *2014-02-07*
- Added `Archive link` to the Custom Board Navigation Rice - Added `Archive link` to the Custom Board Navigation Rice

View File

@ -73,9 +73,7 @@ Config =
'Quote Previewing': [true, 'Show quoted post on hover.'] 'Quote Previewing': [true, 'Show quoted post on hover.']
'Quote Highlighting': [true, 'Highlight the previewed post.'] 'Quote Highlighting': [true, 'Highlight the previewed post.']
'Resurrect Quotes': [true, 'Link dead quotes to the archives.'] 'Resurrect Quotes': [true, 'Link dead quotes to the archives.']
'Mark Quotes of You': [true, 'Add \'(You)\' to quotes linking to your posts.'] 'Quote Markers': [true, 'Add "(You)", "(OP)", "(Cross-thread)", "(Dead)" markers to quote links.']
'Mark OP Quotes': [true, 'Add \'(OP)\' to OP quotes.']
'Mark Cross-thread Quotes': [true, 'Add \'(Cross-thread)\' to cross-threads quotes.']
imageExpansion: imageExpansion:
'Fit width': [true, ''] 'Fit width': [true, '']
'Fit height': [false, ''] 'Fit height': [false, '']

View File

@ -96,9 +96,7 @@ Main =
initFeature 'Quote Inlining', QuoteInline initFeature 'Quote Inlining', QuoteInline
initFeature 'Quote Previewing', QuotePreview initFeature 'Quote Previewing', QuotePreview
initFeature 'Quote Backlinks', QuoteBacklink initFeature 'Quote Backlinks', QuoteBacklink
initFeature 'Mark Quotes of You', QuoteYou initFeature 'Quote Markers', QuoteMarkers
initFeature 'Mark OP Quotes', QuoteOP
initFeature 'Mark Cross-thread Quotes', QuoteCT
initFeature 'Anonymize', Anonymize initFeature 'Anonymize', Anonymize
initFeature 'Color User IDs', IDColor initFeature 'Color User IDs', IDColor
initFeature 'Time Formatting', Time initFeature 'Time Formatting', Time

View File

@ -177,8 +177,11 @@ class Post
# Get quotelinks/backlinks to this post # Get quotelinks/backlinks to this post
# and paint them (Dead). # and paint them (Dead).
for quotelink in Get.allQuotelinksLinkingTo @ when not $.hasClass quotelink, 'deadlink' for quotelink in Get.allQuotelinksLinkingTo @ when not $.hasClass quotelink, 'deadlink'
$.add quotelink, $.tn '\u00A0(Dead)'
$.addClass quotelink, 'deadlink' $.addClass quotelink, 'deadlink'
continue unless Conf['Quote Markers']
post = Get.postFromNode quotelink
{board, thread} = if post.isClone then post.context else post
QuoteMarkers.parseQuotelink board, thread, post, quotelink, true
return return
# XXX tmp fix for 4chan's racing condition # XXX tmp fix for 4chan's racing condition
# giving us false-positive dead posts. # giving us false-positive dead posts.
@ -197,10 +200,12 @@ class Post
for clone in @clones for clone in @clones
clone.resurrect() clone.resurrect()
for quotelink in Get.allQuotelinksLinkingTo @ for quotelink in Get.allQuotelinksLinkingTo @ when $.hasClass quotelink, 'deadlink'
if $.hasClass quotelink, 'deadlink' $.rmClass quotelink, 'deadlink'
quotelink.textContent = quotelink.textContent.replace '\u00A0(Dead)', '' continue unless Conf['Quote Markers']
$.rmClass quotelink, 'deadlink' post = Get.postFromNode quotelink
{board, thread} = if post.isClone then post.context else post
QuoteMarkers.parseQuotelink board, thread, post, quotelink, true
return return
collect: -> collect: ->

View File

@ -192,8 +192,8 @@ Settings =
'Remember QR size': '' 'Remember QR size': ''
'Quote Inline': 'Quote Inlining' 'Quote Inline': 'Quote Inlining'
'Quote Preview': 'Quote Previewing' 'Quote Preview': 'Quote Previewing'
'Indicate OP quote': 'Mark OP Quotes' 'Indicate OP quote': ''
'Indicate Cross-thread Quotes': 'Mark Cross-thread Quotes' 'Indicate Cross-thread Quotes': ''
# filter # filter
'uniqueid': 'uniqueID' 'uniqueid': 'uniqueID'
'mod': 'capcode' 'mod': 'capcode'

View File

@ -24,10 +24,17 @@ QuoteBacklink =
cb: @secondNode cb: @secondNode
firstNode: -> firstNode: ->
return if @isClone or !@quotes.length return if @isClone or !@quotes.length
text = QuoteBacklink.funk @ID
a = $.el 'a', a = $.el 'a',
href: "/#{@board}/res/#{@thread}#p#{@}" href: "/#{@board}/res/#{@thread}#p#{@}"
className: if @isHidden then 'filtered backlink' else 'backlink' className: 'backlink'
textContent: QuoteBacklink.funk @ID textContent: text
if @isHidden
$.addClass a, 'filtered'
if @isDead
$.addClass a, 'deadlink'
if Conf['Quote Markers']
QuoteMarkers.parseQuotelink @board, @thread, @, a, false, text
for quote in @quotes for quote in @quotes
containers = [QuoteBacklink.getContainer quote] containers = [QuoteBacklink.getContainer quote]
if (post = g.posts[quote]) and post.nodes.backlinkContainer if (post = g.posts[quote]) and post.nodes.backlinkContainer

View File

@ -1,22 +0,0 @@
QuoteCT =
init: ->
return if !Conf['Mark Cross-thread Quotes']
# \u00A0 is nbsp
@text = '\u00A0(Cross-thread)'
Post.callbacks.push
name: 'Mark Cross-thread Quotes'
cb: @node
node: ->
# Stop there if it's a clone of a post in the same thread.
return if @isClone and @thread is @context.thread
{board, thread} = if @isClone then @context else @
for quotelink in @nodes.quotelinks
{boardID, threadID} = Get.postDataFromLink quotelink
continue unless threadID # deadlink
if @isClone
quotelink.textContent = quotelink.textContent.replace QuoteCT.text, ''
if boardID is board.ID and threadID isnt thread.ID
$.add quotelink, $.tn QuoteCT.text
return

View File

@ -0,0 +1,39 @@
QuoteMarkers =
init: ->
return if !Conf['Quote Markers']
Post.callbacks.push
name: 'Quote Markers'
cb: @node
node: ->
{board, thread} = if @isClone then @context else @
for quotelink in @nodes.quotelinks
QuoteMarkers.parseQuotelink board, thread, @, quotelink, !!@isClone
return
parseQuotelink: (board, thread, post, quotelink, mayReset, customText) ->
markers = []
{boardID, threadID, postID} = Get.postDataFromLink quotelink
if QR.db?.get {boardID, threadID, postID}
markers.push 'You'
if board.ID is boardID
if thread.ID is postID
markers.push 'OP'
if threadID and threadID isnt thread.ID # threadID is 0 for deadlinks
markers.push 'Cross-thread'
if $.hasClass quotelink, 'deadlink'
markers.push 'Dead'
text = if customText
customText
else if boardID is post.board.ID
">>#{postID}"
else
">>>/#{boardID}/#{postID}"
if markers.length
quotelink.textContent = "#{text}\u00A0(#{markers.join '/'})"
else if mayReset
quotelink.textContent = text

View File

@ -1,29 +0,0 @@
QuoteOP =
init: ->
return if !Conf['Mark OP Quotes']
# \u00A0 is nbsp
@text = '\u00A0(OP)'
Post.callbacks.push
name: 'Mark OP Quotes'
cb: @node
node: ->
# Stop there if it's a clone of a post in the same thread.
return if @isClone and @thread is @context.thread
# Stop there if there's no quotes in that post.
return unless (quotes = @quotes).length
{quotelinks} = @nodes
# rm (OP) from cross-thread quotes.
if @isClone and @thread.fullID in quotes
for quotelink in quotelinks
quotelink.textContent = quotelink.textContent.replace QuoteOP.text, ''
{fullID} = (if @isClone then @context else @).thread
# add (OP) to quotes quoting this context's OP.
return unless fullID in quotes
for quotelink in quotelinks
{boardID, postID} = Get.postDataFromLink quotelink
if "#{boardID}.#{postID}" is fullID
$.add quotelink, $.tn QuoteOP.text
return

View File

@ -1,14 +0,0 @@
QuoteYou =
init: ->
return if !Conf['Mark Quotes of You'] or !Conf['Quick Reply']
# \u00A0 is nbsp
@text = '\u00A0(You)'
Post.callbacks.push
name: 'Mark Quotes of You'
cb: @node
node: ->
return if @isClone
for quotelink in @nodes.quotelinks when QR.db.get Get.postDataFromLink quotelink
$.add quotelink, $.tn QuoteYou.text
return

View File

@ -37,28 +37,20 @@ Quotify =
quoteID = "#{boardID}.#{postID}" quoteID = "#{boardID}.#{postID}"
if post = g.posts[quoteID] if post = g.posts[quoteID]
unless post.isDead # Don't add 'deadlink' when quotifying in an archived post,
# Don't (Dead) when quotifying in an archived post, # and we don't know if the post died yet.
# and we know the post still exists. a = $.el 'a',
a = $.el 'a', href: "/#{boardID}/res/#{post.thread}#p#{postID}"
href: "/#{boardID}/res/#{post.thread}#p#{postID}" className: if post.isDead then 'quotelink deadlink' else 'quotelink'
className: 'quotelink' textContent: quote
textContent: quote $.extend a.dataset, {boardID, threadID: post.thread.ID, postID}
else else if redirect = Redirect.to 'thread', {boardID, postID}
# Replace the .deadlink span if we can redirect.
a = $.el 'a',
href: "/#{boardID}/res/#{post.thread}#p#{postID}"
className: 'quotelink deadlink'
target: '_blank'
textContent: "#{quote}\u00A0(Dead)"
$.extend a.dataset, {boardID, threadID: post.thread.ID, postID}
else if redirect = Redirect.to 'thread', {boardID, threadID: 0, postID}
# Replace the .deadlink span if we can redirect. # Replace the .deadlink span if we can redirect.
a = $.el 'a', a = $.el 'a',
href: redirect href: redirect
className: 'deadlink' className: 'deadlink'
textContent: quote
target: '_blank' target: '_blank'
textContent: "#{quote}\u00A0(Dead)"
if Redirect.to 'post', {boardID, postID} if Redirect.to 'post', {boardID, postID}
# Make it function as a normal quote if we can fetch the post. # Make it function as a normal quote if we can fetch the post.
$.addClass a, 'quotelink' $.addClass a, 'quotelink'
@ -68,7 +60,7 @@ Quotify =
@quotes.push quoteID @quotes.push quoteID
unless a unless a
deadlink.textContent = "#{quote}\u00A0(Dead)" deadlink.textContent = "#{quote}\u00A0(Dead)" if Conf['Quote Markers']
return return
$.replace deadlink, a $.replace deadlink, a