Process threads added to board index by infinite scrolling scripts.
This commit is contained in:
parent
70bcd9dc1b
commit
a133370dc5
@ -2,6 +2,7 @@ Polyfill =
|
|||||||
init: ->
|
init: ->
|
||||||
@toBlob()
|
@toBlob()
|
||||||
$.global @toBlob
|
$.global @toBlob
|
||||||
|
Element::matches or= Element::mozMatchesSelector or Element::webkitMatchesSelector
|
||||||
return
|
return
|
||||||
toBlob: ->
|
toBlob: ->
|
||||||
return if HTMLCanvasElement::toBlob
|
return if HTMLCanvasElement::toBlob
|
||||||
|
|||||||
@ -328,21 +328,11 @@ Main =
|
|||||||
posts = []
|
posts = []
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
Main.addPostsObserver = new MutationObserver Main.addPosts
|
Main.addThreadsObserver = new MutationObserver Main.addThreads
|
||||||
|
Main.addPostsObserver = new MutationObserver Main.addPosts
|
||||||
|
Main.addThreadsObserver.observe board, {childList: true}
|
||||||
|
|
||||||
for threadRoot in $$(s.thread, board)
|
Main.parseThreads $$(s.thread, board), threads, posts, errors
|
||||||
boardObj = if (boardID = threadRoot.dataset.board)
|
|
||||||
boardID = encodeURIComponent boardID
|
|
||||||
g.boards[boardID] or new Board(boardID)
|
|
||||||
else
|
|
||||||
g.BOARD
|
|
||||||
thread = new Thread +threadRoot.id.match(/\d*$/)[0], boardObj
|
|
||||||
thread.nodes.root = threadRoot
|
|
||||||
threads.push thread
|
|
||||||
postRoots = $$ s.postContainer, threadRoot
|
|
||||||
postRoots.unshift threadRoot if Site.isOPContainerThread
|
|
||||||
Main.parsePosts postRoots, thread, posts, errors
|
|
||||||
Main.addPostsObserver.observe threadRoot, {childList: true}
|
|
||||||
Main.handleErrors errors if errors.length
|
Main.handleErrors errors if errors.length
|
||||||
|
|
||||||
if g.VIEW is 'thread'
|
if g.VIEW is 'thread'
|
||||||
@ -358,6 +348,23 @@ Main =
|
|||||||
Main.expectInitFinished = true
|
Main.expectInitFinished = true
|
||||||
$.event '4chanXInitFinished'
|
$.event '4chanXInitFinished'
|
||||||
|
|
||||||
|
parseThreads: (threadRoots, threads, posts, errors) ->
|
||||||
|
for threadRoot in threadRoots
|
||||||
|
boardObj = if (boardID = threadRoot.dataset.board)
|
||||||
|
boardID = encodeURIComponent boardID
|
||||||
|
g.boards[boardID] or new Board(boardID)
|
||||||
|
else
|
||||||
|
g.BOARD
|
||||||
|
threadID = +threadRoot.id.match(/\d*$/)[0]
|
||||||
|
return if boardObj.threads[threadID]?.nodes.root
|
||||||
|
thread = new Thread threadID, boardObj
|
||||||
|
thread.nodes.root = threadRoot
|
||||||
|
threads.push thread
|
||||||
|
postRoots = $$ Site.selectors.postContainer, threadRoot
|
||||||
|
postRoots.unshift threadRoot if Site.isOPContainerThread
|
||||||
|
Main.parsePosts postRoots, thread, posts, errors
|
||||||
|
Main.addPostsObserver.observe threadRoot, {childList: true}
|
||||||
|
|
||||||
parsePosts: (postRoots, thread, posts, errors) ->
|
parsePosts: (postRoots, thread, posts, errors) ->
|
||||||
for postRoot in postRoots when !postRoot.dataset.fullID and $(Site.selectors.comment, postRoot)
|
for postRoot in postRoots when !postRoot.dataset.fullID and $(Site.selectors.comment, postRoot)
|
||||||
try
|
try
|
||||||
@ -369,6 +376,21 @@ Main =
|
|||||||
error: err
|
error: err
|
||||||
return
|
return
|
||||||
|
|
||||||
|
addThreads: (records) ->
|
||||||
|
threadRoots = []
|
||||||
|
for record in records
|
||||||
|
for node in record.addedNodes when node.matches(Site.selectors.thread)
|
||||||
|
threadRoots.push node
|
||||||
|
return unless threadRoots.length
|
||||||
|
threads = []
|
||||||
|
posts = []
|
||||||
|
errors = []
|
||||||
|
Main.parseThreads threadRoots, threads, posts, errors
|
||||||
|
Main.handleErrors errors if errors.length
|
||||||
|
Main.callbackNodes 'Thread', threads
|
||||||
|
Main.callbackNodesDB 'Post', posts, ->
|
||||||
|
$.event 'PostsInserted', null, records[0].target
|
||||||
|
|
||||||
addPosts: (records) ->
|
addPosts: (records) ->
|
||||||
threads = []
|
threads = []
|
||||||
threadsRM = []
|
threadsRM = []
|
||||||
|
|||||||
@ -63,7 +63,7 @@ SW.tinyboard =
|
|||||||
|
|
||||||
selectors:
|
selectors:
|
||||||
board: 'form[name="postcontrols"]'
|
board: 'form[name="postcontrols"]'
|
||||||
thread: 'div[id^="thread_"]'
|
thread: 'div[id^="thread_"]:not([data-cached="yes"])'
|
||||||
threadDivider: 'div[id^="thread_"] > hr:last-of-type'
|
threadDivider: 'div[id^="thread_"] > hr:last-of-type'
|
||||||
summary: '.omitted'
|
summary: '.omitted'
|
||||||
postContainer: '.reply' # postContainer is thread for OP
|
postContainer: '.reply' # postContainer is thread for OP
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user