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)...]
|
for node in [root, $$('[id]', root)...]
|
||||||
node.id = Post.Clone.prefix + node.id
|
node.id = Post.Clone.prefix + node.id
|
||||||
Post.Clone.prefix++
|
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.
|
@nodes = @parseNodes root
|
||||||
# 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
|
|
||||||
|
|
||||||
# Remove inlined posts inside of this post.
|
# Remove inlined posts inside of this post.
|
||||||
for inline in $$ '.inline', post
|
for inline in $$ '.inline', @nodes.post
|
||||||
$.rm inline
|
$.rm inline
|
||||||
for inlined in $$ '.inlined', post
|
for inlined in $$ '.inlined', @nodes.post
|
||||||
$.rmClass inlined, 'inlined'
|
$.rmClass inlined, 'inlined'
|
||||||
|
|
||||||
root.hidden = false # post hiding
|
root.hidden = false # post hiding
|
||||||
$.rmClass root, 'forwarded' # quote inlining
|
$.rmClass root, 'forwarded' # quote inlining
|
||||||
$.rmClass post, 'highlight' # keybind navigation, ID highlighting
|
$.rmClass @nodes.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
|
|
||||||
|
|
||||||
@parseQuotes()
|
@parseQuotes()
|
||||||
@quotes = [@origin.quotes...]
|
@quotes = [@origin.quotes...]
|
||||||
@ -75,7 +37,7 @@ Post.Clone = class extends Post
|
|||||||
@file = {}
|
@file = {}
|
||||||
for key, val of @origin.file
|
for key, val of @origin.file
|
||||||
@file[key] = val
|
@file[key] = val
|
||||||
file = $ '.file', post
|
file = $ '.file', @nodes.post
|
||||||
@file.text = file.firstElementChild
|
@file.text = file.firstElementChild
|
||||||
@file.link = $ '.fileText > a, .fileText-original', file
|
@file.link = $ '.fileText > a, .fileText-original', file
|
||||||
@file.thumb = $ '.fileThumb > [data-md5]', file
|
@file.thumb = $ '.fileThumb > [data-md5]', file
|
||||||
|
|||||||
@ -11,65 +11,26 @@ class Post
|
|||||||
@context = @
|
@context = @
|
||||||
|
|
||||||
root.dataset.fullID = @fullID
|
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.
|
@nodes = @parseNodes root
|
||||||
# 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 = $.hasClass post, 'reply')
|
unless (@isReply = $.hasClass @nodes.post, 'reply')
|
||||||
@thread.OP = @
|
@thread.OP = @
|
||||||
@thread.isArchived = !!$ '.archivedIcon', info
|
@thread.isArchived = !!$ '.archivedIcon', @nodes.info
|
||||||
@thread.isSticky = !!$ '.stickyIcon', info
|
@thread.isSticky = !!$ '.stickyIcon', @nodes.info
|
||||||
@thread.isClosed = @thread.isArchived or !!$ '.closedIcon', info
|
@thread.isClosed = @thread.isArchived or !!$ '.closedIcon', @nodes.info
|
||||||
@thread.kill() if @thread.isArchived
|
@thread.kill() if @thread.isArchived
|
||||||
@nodes.reply = $ '.replylink', info
|
|
||||||
|
|
||||||
@info = {}
|
@info =
|
||||||
@info.nameBlock = if Conf['Anonymize']
|
nameBlock: if Conf['Anonymize'] then 'Anonymous' else @nodes.nameBlock.textContent.trim()
|
||||||
'Anonymous'
|
subject: @nodes.subject?.textContent or undefined
|
||||||
else
|
name: @nodes.name?.textContent
|
||||||
@nodes.nameBlock.textContent.trim()
|
email: if @nodes.email then decodeURIComponent @nodes.email.href[7..]
|
||||||
if subject = $ '.subject', info
|
tripcode: @nodes.tripcode?.textContent
|
||||||
@nodes.subject = subject
|
uniqueID: @nodes.uniqueID?.firstElementChild.textContent
|
||||||
@info.subject = subject.textContent or undefined
|
capcode: @nodes.capcode?.textContent.replace '## ', ''
|
||||||
if name = $ '.name', info
|
flag: @nodes.flag?.title
|
||||||
@nodes.name = name
|
date: if @nodes.date then new Date(@nodes.date.dataset.utc * 1000)
|
||||||
@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
|
|
||||||
|
|
||||||
@parseComment()
|
@parseComment()
|
||||||
@parseQuotes()
|
@parseQuotes()
|
||||||
@ -91,6 +52,40 @@ class Post
|
|||||||
@thread.posts.push @ID, @
|
@thread.posts.push @ID, @
|
||||||
g.posts.push @fullID, @
|
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: ->
|
parseComment: ->
|
||||||
# Merge text nodes and remove empty ones.
|
# Merge text nodes and remove empty ones.
|
||||||
@nodes.comment.normalize()
|
@nodes.comment.normalize()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user