Remove some duplicated code between Post and Post.Clone.
This commit is contained in:
parent
c11054098e
commit
f39b0c03e5
@ -15,56 +15,18 @@ Post.Clone = class extends Post
|
||||
for node in [root, $$('[id]', root)...]
|
||||
node.id = Post.Clone.prefix + node.id
|
||||
Post.Clone.prefix++
|
||||
post = $ '.post', root
|
||||
info = $ '.postInfo', post
|
||||
@nodes =
|
||||
root: root
|
||||
post: post
|
||||
info: info
|
||||
nameBlock: $ '.nameBlock', info
|
||||
quote: $ '.postNum > a:nth-of-type(2)', info
|
||||
comment: $ '.postMessage', post
|
||||
quotelinks: []
|
||||
|
||||
# XXX Edge invalidates HTMLCollections when an ancestor node is inserted into another node.
|
||||
# https://connect.microsoft.com/IE/feedback/details/1198967/ie11-appendchild-provoke-an-error-on-an-htmlcollection
|
||||
if $.engine is 'edge'
|
||||
Object.defineProperty @nodes, 'backlinks',
|
||||
configurable: true
|
||||
enumerable: true
|
||||
get: -> info.getElementsByClassName 'backlink'
|
||||
else
|
||||
@nodes.backlinks = info.getElementsByClassName 'backlink'
|
||||
|
||||
unless @isReply
|
||||
@nodes.reply = $ '.replylink', info
|
||||
@nodes = @parseNodes root
|
||||
|
||||
# Remove inlined posts inside of this post.
|
||||
for inline in $$ '.inline', post
|
||||
for inline in $$ '.inline', @nodes.post
|
||||
$.rm inline
|
||||
for inlined in $$ '.inlined', post
|
||||
for inlined in $$ '.inlined', @nodes.post
|
||||
$.rmClass inlined, 'inlined'
|
||||
|
||||
root.hidden = false # post hiding
|
||||
$.rmClass root, 'forwarded' # quote inlining
|
||||
$.rmClass post, 'highlight' # keybind navigation, ID highlighting
|
||||
|
||||
if nodes.subject
|
||||
@nodes.subject = $ '.subject', info
|
||||
if nodes.name
|
||||
@nodes.name = $ '.name', info
|
||||
if nodes.email
|
||||
@nodes.email = $ '.useremail', info
|
||||
if nodes.tripcode
|
||||
@nodes.tripcode = $ '.postertrip', info
|
||||
if nodes.uniqueID
|
||||
@nodes.uniqueID = $ '.posteruid', info
|
||||
if nodes.capcode
|
||||
@nodes.capcode = $ '.capcode.hand', info
|
||||
if nodes.flag
|
||||
@nodes.flag = $ '.flag, .countryFlag', info
|
||||
if nodes.date
|
||||
@nodes.date = $ '.dateTime', info
|
||||
$.rmClass root, 'forwarded' # quote inlining
|
||||
$.rmClass @nodes.post, 'highlight' # keybind navigation, ID highlighting
|
||||
|
||||
@parseQuotes()
|
||||
@quotes = [@origin.quotes...]
|
||||
@ -75,7 +37,7 @@ Post.Clone = class extends Post
|
||||
@file = {}
|
||||
for key, val of @origin.file
|
||||
@file[key] = val
|
||||
file = $ '.file', post
|
||||
file = $ '.file', @nodes.post
|
||||
@file.text = file.firstElementChild
|
||||
@file.link = $ '.fileText > a, .fileText-original', file
|
||||
@file.thumb = $ '.fileThumb > [data-md5]', file
|
||||
|
||||
@ -11,65 +11,26 @@ class Post
|
||||
@context = @
|
||||
|
||||
root.dataset.fullID = @fullID
|
||||
post = $ '.post', root
|
||||
info = $ '.postInfo', post
|
||||
@nodes =
|
||||
root: root
|
||||
post: post
|
||||
info: info
|
||||
nameBlock: $ '.nameBlock', info
|
||||
quote: $ '.postNum > a:nth-of-type(2)', info
|
||||
comment: $ '.postMessage', post
|
||||
links: []
|
||||
quotelinks: []
|
||||
|
||||
# XXX Edge invalidates HTMLCollections when an ancestor node is inserted into another node.
|
||||
# https://connect.microsoft.com/IE/feedback/details/1198967/ie11-appendchild-provoke-an-error-on-an-htmlcollection
|
||||
if $.engine is 'edge'
|
||||
Object.defineProperty @nodes, 'backlinks',
|
||||
configurable: true
|
||||
enumerable: true
|
||||
get: -> info.getElementsByClassName 'backlink'
|
||||
else
|
||||
@nodes.backlinks = info.getElementsByClassName 'backlink'
|
||||
@nodes = @parseNodes root
|
||||
|
||||
unless (@isReply = $.hasClass post, 'reply')
|
||||
unless (@isReply = $.hasClass @nodes.post, 'reply')
|
||||
@thread.OP = @
|
||||
@thread.isArchived = !!$ '.archivedIcon', info
|
||||
@thread.isSticky = !!$ '.stickyIcon', info
|
||||
@thread.isClosed = @thread.isArchived or !!$ '.closedIcon', info
|
||||
@thread.isArchived = !!$ '.archivedIcon', @nodes.info
|
||||
@thread.isSticky = !!$ '.stickyIcon', @nodes.info
|
||||
@thread.isClosed = @thread.isArchived or !!$ '.closedIcon', @nodes.info
|
||||
@thread.kill() if @thread.isArchived
|
||||
@nodes.reply = $ '.replylink', info
|
||||
|
||||
@info = {}
|
||||
@info.nameBlock = if Conf['Anonymize']
|
||||
'Anonymous'
|
||||
else
|
||||
@nodes.nameBlock.textContent.trim()
|
||||
if subject = $ '.subject', info
|
||||
@nodes.subject = subject
|
||||
@info.subject = subject.textContent or undefined
|
||||
if name = $ '.name', info
|
||||
@nodes.name = name
|
||||
@info.name = name.textContent
|
||||
if email = $ '.useremail', info
|
||||
@nodes.email = email
|
||||
@info.email = decodeURIComponent email.href[7..]
|
||||
if tripcode = $ '.postertrip', info
|
||||
@nodes.tripcode = tripcode
|
||||
@info.tripcode = tripcode.textContent
|
||||
if uniqueID = $ '.posteruid', info
|
||||
@nodes.uniqueID = uniqueID
|
||||
@info.uniqueID = uniqueID.firstElementChild.textContent
|
||||
if capcode = $ '.capcode.hand', info
|
||||
@nodes.capcode = capcode
|
||||
@info.capcode = capcode.textContent.replace '## ', ''
|
||||
if flag = $ '.flag, .countryFlag', info
|
||||
@nodes.flag = flag
|
||||
@info.flag = flag.title
|
||||
if date = $ '.dateTime', info
|
||||
@nodes.date = date
|
||||
@info.date = new Date date.dataset.utc * 1000
|
||||
@info =
|
||||
nameBlock: if Conf['Anonymize'] then 'Anonymous' else @nodes.nameBlock.textContent.trim()
|
||||
subject: @nodes.subject?.textContent or undefined
|
||||
name: @nodes.name?.textContent
|
||||
email: if @nodes.email then decodeURIComponent @nodes.email.href[7..]
|
||||
tripcode: @nodes.tripcode?.textContent
|
||||
uniqueID: @nodes.uniqueID?.firstElementChild.textContent
|
||||
capcode: @nodes.capcode?.textContent.replace '## ', ''
|
||||
flag: @nodes.flag?.title
|
||||
date: if @nodes.date then new Date(@nodes.date.dataset.utc * 1000)
|
||||
|
||||
@parseComment()
|
||||
@parseQuotes()
|
||||
@ -91,6 +52,40 @@ class Post
|
||||
@thread.posts.push @ID, @
|
||||
g.posts.push @fullID, @
|
||||
|
||||
parseNodes: (root) ->
|
||||
post = $ '.post', root
|
||||
info = $ '.postInfo', post
|
||||
nodes =
|
||||
root: root
|
||||
post: post
|
||||
info: info
|
||||
subject: $ '.subject', info
|
||||
name: $ '.name', info
|
||||
email: $ '.useremail', info
|
||||
tripcode: $ '.postertrip', info
|
||||
uniqueID: $ '.posteruid', info
|
||||
capcode: $ '.capcode.hand', info
|
||||
flag: $ '.flag, .countryFlag', info
|
||||
date: $ '.dateTime', info
|
||||
nameBlock: $ '.nameBlock', info
|
||||
quote: $ '.postNum > a:nth-of-type(2)', info
|
||||
reply: $ '.replylink', info
|
||||
comment: $ '.postMessage', post
|
||||
links: []
|
||||
quotelinks: []
|
||||
|
||||
# XXX Edge invalidates HTMLCollections when an ancestor node is inserted into another node.
|
||||
# https://connect.microsoft.com/IE/feedback/details/1198967/ie11-appendchild-provoke-an-error-on-an-htmlcollection
|
||||
if $.engine is 'edge'
|
||||
Object.defineProperty nodes, 'backlinks',
|
||||
configurable: true
|
||||
enumerable: true
|
||||
get: -> info.getElementsByClassName 'backlink'
|
||||
else
|
||||
nodes.backlinks = info.getElementsByClassName 'backlink'
|
||||
|
||||
nodes
|
||||
|
||||
parseComment: ->
|
||||
# Merge text nodes and remove empty ones.
|
||||
@nodes.comment.normalize()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user