Close #1106
This commit is contained in:
parent
63cd0aa164
commit
be7a4052fd
@ -7,13 +7,21 @@ ExpandThread =
|
|||||||
cb: @node
|
cb: @node
|
||||||
node: ->
|
node: ->
|
||||||
return unless span = $.x 'following-sibling::span[contains(@class,"summary")][1]', @OP.nodes.root
|
return unless span = $.x 'following-sibling::span[contains(@class,"summary")][1]', @OP.nodes.root
|
||||||
|
[posts, files] = span.textContent.match /\d+/g
|
||||||
a = $.el 'a',
|
a = $.el 'a',
|
||||||
textContent: "+ #{span.textContent}"
|
textContent: ExpandThread.text '+', posts, files
|
||||||
className: 'summary'
|
className: 'summary'
|
||||||
href: 'javascript:;'
|
href: 'javascript:;'
|
||||||
$.on a, 'click', ExpandThread.cbToggle
|
$.on a, 'click', ExpandThread.cbToggle
|
||||||
$.replace span, a
|
$.replace span, a
|
||||||
|
|
||||||
|
text: (status, posts, files) ->
|
||||||
|
text = [status]
|
||||||
|
text.push "#{posts} post#{if posts > 1 then 's' else ''}"
|
||||||
|
text.push "and #{files} image repl#{if files > 1 then 'ies' else 'y'}" if +files
|
||||||
|
text.push if status is '-' then 'shown' else 'omitted'
|
||||||
|
text.join(' ') + '.'
|
||||||
|
|
||||||
cbToggle: ->
|
cbToggle: ->
|
||||||
ExpandThread.toggle Get.threadFromRoot @parentNode
|
ExpandThread.toggle Get.threadFromRoot @parentNode
|
||||||
|
|
||||||
@ -29,14 +37,16 @@ ExpandThread =
|
|||||||
thread.isExpanded = true
|
thread.isExpanded = true
|
||||||
return
|
return
|
||||||
thread.isExpanded = 'loading'
|
thread.isExpanded = 'loading'
|
||||||
a.textContent = a.textContent.replace '+', '× Loading...'
|
[posts, files] = a.textContent.match /\d+/g
|
||||||
|
a.textContent = ExpandThread.text '...', posts, files
|
||||||
$.cache "//api.4chan.org/#{thread.board}/res/#{thread}.json", ->
|
$.cache "//api.4chan.org/#{thread.board}/res/#{thread}.json", ->
|
||||||
ExpandThread.parse @, thread, a
|
ExpandThread.parse @, thread, a
|
||||||
|
|
||||||
when 'loading'
|
when 'loading'
|
||||||
thread.isExpanded = false
|
thread.isExpanded = false
|
||||||
return unless a
|
return unless a
|
||||||
a.textContent = a.textContent.replace '× Loading...', '+'
|
[posts, files] = a.textContent.match /\d+/g
|
||||||
|
a.textContent = ExpandThread.text '+', posts, files
|
||||||
|
|
||||||
when true
|
when true
|
||||||
thread.isExpanded = false
|
thread.isExpanded = false
|
||||||
@ -52,12 +62,16 @@ ExpandThread =
|
|||||||
for post in [thread.OP.nodes.root].concat posts[-num..]
|
for post in [thread.OP.nodes.root].concat posts[-num..]
|
||||||
ExpandComment.contract Get.postFromRoot post
|
ExpandComment.contract Get.postFromRoot post
|
||||||
return unless a
|
return unless a
|
||||||
a.textContent = a.textContent.replace '-', '+'
|
postsCount = 0
|
||||||
|
filesCount = 0
|
||||||
for reply in posts[...-num]
|
for reply in posts[...-num]
|
||||||
if Conf['Quote Inlining']
|
if Conf['Quote Inlining']
|
||||||
# rm clones
|
# rm clones
|
||||||
inlined.click() while inlined = $ '.inlined', reply
|
inlined.click() while inlined = $ '.inlined', reply
|
||||||
|
postsCount++
|
||||||
|
filesCount++ if 'file' of Get.postFromRoot reply
|
||||||
$.rm reply
|
$.rm reply
|
||||||
|
a.textContent = ExpandThread.text '+', postsCount, filesCount
|
||||||
return
|
return
|
||||||
|
|
||||||
parse: (req, thread, a) ->
|
parse: (req, thread, a) ->
|
||||||
@ -68,30 +82,35 @@ ExpandThread =
|
|||||||
return
|
return
|
||||||
|
|
||||||
thread.isExpanded = true
|
thread.isExpanded = true
|
||||||
a.textContent = a.textContent.replace '× Loading...', '-'
|
|
||||||
|
|
||||||
{posts} = JSON.parse req.response
|
{posts} = JSON.parse req.response
|
||||||
if spoilerRange = posts.shift().custom_spoiler
|
if spoilerRange = posts.shift().custom_spoiler
|
||||||
Build.spoilerRange[thread.board] = spoilerRange
|
Build.spoilerRange[thread.board] = spoilerRange
|
||||||
|
|
||||||
postsObj = []
|
postsObj = []
|
||||||
postsRoot = []
|
postsRoot = []
|
||||||
for post in posts
|
filesCount = 0
|
||||||
if post = thread.posts[post.no]
|
for reply in posts
|
||||||
|
if post = thread.posts[reply.no]
|
||||||
|
filesCount++ if 'file' of post
|
||||||
postsRoot.push post.nodes.root
|
postsRoot.push post.nodes.root
|
||||||
continue
|
continue
|
||||||
root = Build.postFromObject post, thread.board.ID
|
root = Build.postFromObject reply, thread.board.ID
|
||||||
post = new Post root, thread, thread.board
|
post = new Post root, thread, thread.board
|
||||||
link = $ 'a[title="Highlight this post"]', root
|
link = $ 'a[title="Highlight this post"]', root
|
||||||
link.href = "res/#{thread}#p#{post}"
|
link.href = "res/#{thread}#p#{post}"
|
||||||
link.nextSibling.href = "res/#{thread}#q#{post}"
|
link.nextSibling.href = "res/#{thread}#q#{post}"
|
||||||
|
filesCount++ if 'file' of post
|
||||||
postsObj.push post
|
postsObj.push post
|
||||||
postsRoot.push root
|
postsRoot.push root
|
||||||
Main.callbackNodes Post, postsObj
|
Main.callbackNodes Post, postsObj
|
||||||
$.after a, postsRoot
|
$.after a, postsRoot
|
||||||
|
|
||||||
|
postsCount = postsRoot.length
|
||||||
|
a.textContent = ExpandThread.text '-', postsCount, filesCount
|
||||||
|
|
||||||
# Enable 4chan features.
|
# Enable 4chan features.
|
||||||
if Conf['Enable 4chan\'s Extension']
|
if Conf['Enable 4chan\'s Extension']
|
||||||
$.globalEval "Parser.parseThread(#{thread.ID}, 1, #{postsRoot.length})"
|
$.globalEval "Parser.parseThread(#{thread.ID}, 1, #{postsCount})"
|
||||||
else
|
else
|
||||||
Fourchan.parseThread thread.ID, 1, postsRoot.length
|
Fourchan.parseThread thread.ID, 1, postsCount
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user