diff --git a/src/General/Polyfill.coffee b/src/General/Polyfill.coffee index 147035396..b7aea125b 100644 --- a/src/General/Polyfill.coffee +++ b/src/General/Polyfill.coffee @@ -2,6 +2,7 @@ Polyfill = init: -> @toBlob() $.global @toBlob + Element::matches or= Element::mozMatchesSelector or Element::webkitMatchesSelector return toBlob: -> return if HTMLCanvasElement::toBlob diff --git a/src/main/Main.coffee b/src/main/Main.coffee index b9f3abc80..9f39bb877 100644 --- a/src/main/Main.coffee +++ b/src/main/Main.coffee @@ -328,21 +328,11 @@ Main = posts = [] 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) - 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.parseThreads $$(s.thread, board), threads, posts, errors Main.handleErrors errors if errors.length if g.VIEW is 'thread' @@ -358,6 +348,23 @@ Main = Main.expectInitFinished = true $.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) -> for postRoot in postRoots when !postRoot.dataset.fullID and $(Site.selectors.comment, postRoot) try @@ -369,6 +376,21 @@ Main = error: err 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) -> threads = [] threadsRM = [] diff --git a/src/site/SW.tinyboard.coffee b/src/site/SW.tinyboard.coffee index 294441c4d..0c6fb56a6 100644 --- a/src/site/SW.tinyboard.coffee +++ b/src/site/SW.tinyboard.coffee @@ -63,7 +63,7 @@ SW.tinyboard = selectors: board: 'form[name="postcontrols"]' - thread: 'div[id^="thread_"]' + thread: 'div[id^="thread_"]:not([data-cached="yes"])' threadDivider: 'div[id^="thread_"] > hr:last-of-type' summary: '.omitted' postContainer: '.reply' # postContainer is thread for OP