72 lines
2.3 KiB
CoffeeScript
72 lines
2.3 KiB
CoffeeScript
Get =
|
|
threadExcerpt: (thread) ->
|
|
{OP} = thread
|
|
excerpt = ("/#{thread.board}/ - ") + (
|
|
OP.info.subject?.trim() or
|
|
OP.commentDisplay().replace(/\n+/g, ' // ') or
|
|
OP.file?.name or
|
|
"No.#{OP}")
|
|
return "#{excerpt[...70]}..." if excerpt.length > 73
|
|
excerpt
|
|
threadFromRoot: (root) ->
|
|
return null unless root?
|
|
g.threads["#{g.BOARD}.#{root.id[1..]}"]
|
|
threadFromNode: (node) ->
|
|
Get.threadFromRoot $.x 'ancestor-or-self::div[contains(concat(" ",@class," ")," thread ")]', node
|
|
postFromRoot: (root) ->
|
|
return null unless root?
|
|
post = g.posts[root.dataset.fullID]
|
|
index = root.dataset.clone
|
|
if index then post.clones[index] else post
|
|
postFromNode: (root) ->
|
|
Get.postFromRoot $.x 'ancestor-or-self::div[contains(@class,"postContainer")][1]', root
|
|
postDataFromLink: (link) ->
|
|
if link.hostname is 'boards.4chan.org'
|
|
path = link.pathname.split /\/+/
|
|
boardID = path[1]
|
|
threadID = path[3]
|
|
postID = if link.hash then link.hash[2..] else path[3]
|
|
else # resurrected quote
|
|
{boardID, threadID, postID} = link.dataset
|
|
threadID or= 0
|
|
return {
|
|
boardID: boardID
|
|
threadID: +threadID
|
|
postID: +postID
|
|
}
|
|
allQuotelinksLinkingTo: (post) ->
|
|
# Get quotelinks & backlinks linking to the given post.
|
|
quotelinks = []
|
|
{posts} = g
|
|
{fullID} = post
|
|
handleQuotes = (qPost, type) ->
|
|
quotelinks.push qPost.nodes[type]...
|
|
quotelinks.push clone.nodes[type]... for clone in qPost.clones
|
|
return
|
|
# First:
|
|
# In every posts,
|
|
# if it did quote this post,
|
|
# get all their backlinks.
|
|
posts.forEach (qPost) ->
|
|
if fullID in qPost.quotes
|
|
handleQuotes qPost, 'quotelinks'
|
|
|
|
# Second:
|
|
# If we have quote backlinks:
|
|
# in all posts this post quoted
|
|
# and their clones,
|
|
# get all of their backlinks.
|
|
if Conf['Quote Backlinks']
|
|
handleQuotes qPost, 'backlinks' for quote in post.quotes when qPost = posts[quote]
|
|
|
|
# Third:
|
|
# Filter out irrelevant quotelinks.
|
|
quotelinks.filter (quotelink) ->
|
|
{boardID, postID} = Get.postDataFromLink quotelink
|
|
boardID is post.board.ID and postID is post.ID
|
|
|
|
scriptData: ->
|
|
for script in $$ 'script:not([src])', d.head
|
|
return script.textContent if /\bcooldowns *=/.test script.textContent
|
|
''
|