diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index df16a79dc..db4c49811 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -1519,8 +1519,15 @@ })(); RandomAccessList = (function() { - function RandomAccessList() { + function RandomAccessList(items) { + var item, _i, _len; this.length = 0; + if (items) { + for (_i = 0, _len = items.length; _i < _len; _i++) { + item = items[_i]; + this.push(item); + } + } } RandomAccessList.prototype.push = function(data) { @@ -1589,6 +1596,15 @@ return this.rm(this.first.ID); }; + RandomAccessList.prototype.order = function() { + var item, order; + order = [item = this.first]; + while (item = item.next) { + order.push(item); + } + return order; + }; + RandomAccessList.prototype.rm = function(ID) { var item; item = this[ID]; @@ -2738,46 +2754,44 @@ return Main.callbackNodes(Post, posts); }, sort: function() { - var cnd, fn, i, item, items, node, nodes, sortedThreadIDs, threadID, _i, _j, _len, _len1; + var cnd, fn, i, item, items, liveThreadData, liveThreadIDs, nodes, sortedNodes, sortedThreadIDs, threadID, _i, _len; + liveThreadIDs = Index.liveThreadIDs, liveThreadData = Index.liveThreadData; sortedThreadIDs = { - lastreply: __slice.call(Index.liveThreadData).sort(function(a, b) { - if ('last_replies' in a) { - a = a.last_replies[a.last_replies.length - 1]; + lastreply: __slice.call(liveThreadData).sort(function(a, b) { + var num; + if ((num = a.last_replies)) { + a = num[num.length - 1]; } - if ('last_replies' in b) { - b = b.last_replies[b.last_replies.length - 1]; + if ((num = b.last_replies)) { + b = num[num.length - 1]; } return b.no - a.no; - }).map(function(data) { - return data.no; + }).map(function(post) { + return post.no; }), - bump: Index.liveThreadIDs, - birth: __slice.call(Index.liveThreadIDs).sort(function(a, b) { + bump: liveThreadIDs, + birth: __slice.call(liveThreadIDs).sort(function(a, b) { return b - a; }), - replycount: __slice.call(Index.liveThreadData).sort(function(a, b) { + replycount: __slice.call(liveThreadData).sort(function(a, b) { return b.replies - a.replies; - }).map(function(data) { - return data.no; + }).map(function(post) { + return post.no; }), - filecount: __slice.call(Index.liveThreadData).sort(function(a, b) { + filecount: __slice.call(liveThreadData).sort(function(a, b) { return b.images - a.images; - }).map(function(data) { - return data.no; + }).map(function(post) { + return post.no; }) }[Conf['Index Sort']]; - Index.sortedNodes = new RandomAccessList; + Index.sortedNodes = sortedNodes = new RandomAccessList; nodes = Index.nodes; for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) { threadID = sortedThreadIDs[_i]; - Index.sortedNodes.push(nodes[Index.liveThreadIDs.indexOf(threadID)]); + sortedNodes.push(nodes[Index.liveThreadIDs.indexOf(threadID)]); } if (Index.isSearching && (nodes = Index.querySearch(Index.searchInput.value))) { - Index.sortedNodes = new RandomAccessList; - for (_j = 0, _len1 = nodes.length; _j < _len1; _j++) { - node = nodes[_j]; - Index.sortedNodes.push(node); - } + Index.sortedNodes = new RandomAccessList(nodes); } items = [ { @@ -2809,10 +2823,10 @@ var j, offset, sortedNodes, target, threadRoot; offset = 0; sortedNodes = Index.sortedNodes; - threadRoot = Index.sortedNodes.first; + threadRoot = sortedNodes.first; while (threadRoot) { if (match(Get.threadFromRoot(threadRoot.data))) { - target = Index.sortedNodes.first; + target = sortedNodes.first; j = 0; while (j++ < offset) { target = target.next; @@ -2830,11 +2844,9 @@ if (Conf['Index Mode'] !== 'all pages') { nodes = Index.buildSinglePage(Index.getCurrentPage()); } else { - nodes = []; - target = Index.sortedNodes.first; - while (target) { + nodes = [(target = Index.sortedNodes.first).data]; + while (target = target.next) { nodes.push(target.data); - target = target.next; } } $.rmAll(Index.root); @@ -2845,17 +2857,15 @@ return Index.buildStructure(nodes); }, buildSinglePage: function(pageNum) { - var end, i, nodes, nodesPerPage, offset, target; + var end, nodes, nodesPerPage, offset, target; nodes = []; nodesPerPage = Index.threadsNumPerPage; offset = nodesPerPage * pageNum; end = offset + nodesPerPage; - target = Index.sortedNodes.first; - i = 0; - while (i <= end) { - if (offset <= i++) { - nodes.push(target.data); - } + target = Index.sortedNodes.order()[offset]; + Index.sortedNodes; + while ((offset++ <= end) && target) { + nodes.push(target.data); target = target.next; } return nodes; @@ -5228,14 +5238,18 @@ return QuoteThreading.force(); }, force: function() { - return g.posts.forEach(function(post) { + g.posts.forEach(function(post) { if (post.cb) { return post.cb(true); } }); + if (Conf['Unread Count'] && Unread.thread.OP.nodes.root.parentElement.parentElement) { + Unread.read(); + return Unread.update(); + } }, node: function() { - var keys, len, post, posts, quote, _i, _len, _ref; + var keys, len, posts, quote, _i, _len, _ref; posts = g.posts; if (this.isClone || !QuoteThreading.enabled) { return; @@ -5243,7 +5257,7 @@ if (Conf['Unread Count']) { Unread.posts.push(this); } - if (this.thread.OP === this || !(post = posts[this.fullID]) || post.isHidden) { + if (this.thread.OP === this || this.isHidden) { return; } keys = []; @@ -5291,10 +5305,10 @@ if (!Conf['Unread Count']) { return true; } - if (posts[post.ID]) { - posts.after(post, this); + if (post = posts[post.ID]) { + posts.after(post, posts[this.ID]); } else { - posts.prepend(this); + posts.prepend(posts[this.ID]); } return true; }, @@ -9891,7 +9905,7 @@ return; } if (post = Unread.posts.first) { - while (root = $.x('preceding-sibling::div[contains(@class,"replyContainer")][1]', post.nodes.root)) { + while (root = $.x('preceding-sibling::div[contains(@class,"replyContainer")][1]', post.data.nodes.root)) { if (!(post = Get.postFromRoot(root)).isHidden) { break; } @@ -9935,7 +9949,7 @@ return Unread.update(); }, addPosts: function(posts) { - var ID, post, _i, _len, _ref; + var ID, post, _i, _len, _ref, _ref1; for (_i = 0, _len = posts.length; _i < _len; _i++) { post = posts[_i]; ID = post.ID; @@ -9952,7 +9966,7 @@ Unread.addPostQuotingYou(post); } if (Conf['Unread Line']) { - Unread.setLine((_ref = Unread.posts.first.data, __indexOf.call(posts, _ref) >= 0)); + Unread.setLine((_ref = (_ref1 = Unread.posts.first) != null ? _ref1.data : void 0, __indexOf.call(posts, _ref) >= 0)); } Unread.read(); return Unread.update(); @@ -10001,16 +10015,17 @@ } }, readSinglePost: function(post) { - var ID, i; + var ID, i, posts; ID = post.ID; - if (!Unread.posts[ID]) { + posts = Unread.posts; + if (!posts[ID]) { return; } - if (post === Unread.posts.first) { + if (post === posts.first) { Unread.lastReadPost = ID; Unread.saveLastReadPost(); } - Unread.posts.rm(ID); + posts.rm(ID); if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) { Unread.postsQuotingYou.splice(i, 1); } @@ -10034,10 +10049,10 @@ height = doc.clientHeight; posts = Unread.posts; while (post = posts.first) { - ID = post.ID, data = post.data; - if (!(Header.getBottomOf(data.nodes.root) > -1)) { + if (!(Header.getBottomOf(post.data.nodes.root) > -1)) { break; } + ID = post.ID, data = post.data; posts.rm(ID); if (Conf['Mark Quotes of You'] && QR.db.get({ boardID: data.board.ID, @@ -10077,8 +10092,8 @@ if (!(post = Unread.posts.first)) { return $.rm(Unread.hr); } - if ($.x('preceding-sibling::div[contains(@class,"replyContainer")]', post.nodes.root)) { - return $.before(post.nodes.root, Unread.hr); + if ($.x('preceding-sibling::div[contains(@class,"replyContainer")]', post.data.nodes.root)) { + return $.before(post.data.nodes.root, Unread.hr); } }, update: function() { @@ -12092,7 +12107,7 @@ err = _error; error = [ { - message: "Quote Threading Failed.", + message: "" + name + " Failed.", error: err } ]; @@ -12323,7 +12338,8 @@ } Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Post, posts); - Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading']); + Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']); + Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']); Navigate.buildThread(); return Header.hashScroll.call(window); }, @@ -12333,7 +12349,6 @@ $.rmAll(board); $.add(board, [Navigate.threadRoot, $.el('hr')]); if (Conf['Unread Count']) { - Navigate.ready('Unread Count', Unread.ready, !Conf['Quote Threading']); Unread.read(); return Unread.update(); } diff --git a/builds/crx/script.js b/builds/crx/script.js index 3613fc935..d7c282fa4 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1525,8 +1525,15 @@ })(); RandomAccessList = (function() { - function RandomAccessList() { + function RandomAccessList(items) { + var item, _i, _len; this.length = 0; + if (items) { + for (_i = 0, _len = items.length; _i < _len; _i++) { + item = items[_i]; + this.push(item); + } + } } RandomAccessList.prototype.push = function(data) { @@ -1595,6 +1602,15 @@ return this.rm(this.first.ID); }; + RandomAccessList.prototype.order = function() { + var item, order; + order = [item = this.first]; + while (item = item.next) { + order.push(item); + } + return order; + }; + RandomAccessList.prototype.rm = function(ID) { var item; item = this[ID]; @@ -2748,46 +2764,44 @@ return Main.callbackNodes(Post, posts); }, sort: function() { - var cnd, fn, i, item, items, node, nodes, sortedThreadIDs, threadID, _i, _j, _len, _len1; + var cnd, fn, i, item, items, liveThreadData, liveThreadIDs, nodes, sortedNodes, sortedThreadIDs, threadID, _i, _len; + liveThreadIDs = Index.liveThreadIDs, liveThreadData = Index.liveThreadData; sortedThreadIDs = { - lastreply: __slice.call(Index.liveThreadData).sort(function(a, b) { - if ('last_replies' in a) { - a = a.last_replies[a.last_replies.length - 1]; + lastreply: __slice.call(liveThreadData).sort(function(a, b) { + var num; + if ((num = a.last_replies)) { + a = num[num.length - 1]; } - if ('last_replies' in b) { - b = b.last_replies[b.last_replies.length - 1]; + if ((num = b.last_replies)) { + b = num[num.length - 1]; } return b.no - a.no; - }).map(function(data) { - return data.no; + }).map(function(post) { + return post.no; }), - bump: Index.liveThreadIDs, - birth: __slice.call(Index.liveThreadIDs).sort(function(a, b) { + bump: liveThreadIDs, + birth: __slice.call(liveThreadIDs).sort(function(a, b) { return b - a; }), - replycount: __slice.call(Index.liveThreadData).sort(function(a, b) { + replycount: __slice.call(liveThreadData).sort(function(a, b) { return b.replies - a.replies; - }).map(function(data) { - return data.no; + }).map(function(post) { + return post.no; }), - filecount: __slice.call(Index.liveThreadData).sort(function(a, b) { + filecount: __slice.call(liveThreadData).sort(function(a, b) { return b.images - a.images; - }).map(function(data) { - return data.no; + }).map(function(post) { + return post.no; }) }[Conf['Index Sort']]; - Index.sortedNodes = new RandomAccessList; + Index.sortedNodes = sortedNodes = new RandomAccessList; nodes = Index.nodes; for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) { threadID = sortedThreadIDs[_i]; - Index.sortedNodes.push(nodes[Index.liveThreadIDs.indexOf(threadID)]); + sortedNodes.push(nodes[Index.liveThreadIDs.indexOf(threadID)]); } if (Index.isSearching && (nodes = Index.querySearch(Index.searchInput.value))) { - Index.sortedNodes = new RandomAccessList; - for (_j = 0, _len1 = nodes.length; _j < _len1; _j++) { - node = nodes[_j]; - Index.sortedNodes.push(node); - } + Index.sortedNodes = new RandomAccessList(nodes); } items = [ { @@ -2819,10 +2833,10 @@ var j, offset, sortedNodes, target, threadRoot; offset = 0; sortedNodes = Index.sortedNodes; - threadRoot = Index.sortedNodes.first; + threadRoot = sortedNodes.first; while (threadRoot) { if (match(Get.threadFromRoot(threadRoot.data))) { - target = Index.sortedNodes.first; + target = sortedNodes.first; j = 0; while (j++ < offset) { target = target.next; @@ -2840,11 +2854,9 @@ if (Conf['Index Mode'] !== 'all pages') { nodes = Index.buildSinglePage(Index.getCurrentPage()); } else { - nodes = []; - target = Index.sortedNodes.first; - while (target) { + nodes = [(target = Index.sortedNodes.first).data]; + while (target = target.next) { nodes.push(target.data); - target = target.next; } } $.rmAll(Index.root); @@ -2855,17 +2867,15 @@ return Index.buildStructure(nodes); }, buildSinglePage: function(pageNum) { - var end, i, nodes, nodesPerPage, offset, target; + var end, nodes, nodesPerPage, offset, target; nodes = []; nodesPerPage = Index.threadsNumPerPage; offset = nodesPerPage * pageNum; end = offset + nodesPerPage; - target = Index.sortedNodes.first; - i = 0; - while (i <= end) { - if (offset <= i++) { - nodes.push(target.data); - } + target = Index.sortedNodes.order()[offset]; + Index.sortedNodes; + while ((offset++ <= end) && target) { + nodes.push(target.data); target = target.next; } return nodes; @@ -5231,14 +5241,18 @@ return QuoteThreading.force(); }, force: function() { - return g.posts.forEach(function(post) { + g.posts.forEach(function(post) { if (post.cb) { return post.cb(true); } }); + if (Conf['Unread Count'] && Unread.thread.OP.nodes.root.parentElement.parentElement) { + Unread.read(); + return Unread.update(); + } }, node: function() { - var keys, len, post, posts, quote, _i, _len, _ref; + var keys, len, posts, quote, _i, _len, _ref; posts = g.posts; if (this.isClone || !QuoteThreading.enabled) { return; @@ -5246,7 +5260,7 @@ if (Conf['Unread Count']) { Unread.posts.push(this); } - if (this.thread.OP === this || !(post = posts[this.fullID]) || post.isHidden) { + if (this.thread.OP === this || this.isHidden) { return; } keys = []; @@ -5294,10 +5308,10 @@ if (!Conf['Unread Count']) { return true; } - if (posts[post.ID]) { - posts.after(post, this); + if (post = posts[post.ID]) { + posts.after(post, posts[this.ID]); } else { - posts.prepend(this); + posts.prepend(posts[this.ID]); } return true; }, @@ -9874,7 +9888,7 @@ return; } if (post = Unread.posts.first) { - while (root = $.x('preceding-sibling::div[contains(@class,"replyContainer")][1]', post.nodes.root)) { + while (root = $.x('preceding-sibling::div[contains(@class,"replyContainer")][1]', post.data.nodes.root)) { if (!(post = Get.postFromRoot(root)).isHidden) { break; } @@ -9918,7 +9932,7 @@ return Unread.update(); }, addPosts: function(posts) { - var ID, post, _i, _len, _ref; + var ID, post, _i, _len, _ref, _ref1; for (_i = 0, _len = posts.length; _i < _len; _i++) { post = posts[_i]; ID = post.ID; @@ -9935,7 +9949,7 @@ Unread.addPostQuotingYou(post); } if (Conf['Unread Line']) { - Unread.setLine((_ref = Unread.posts.first.data, __indexOf.call(posts, _ref) >= 0)); + Unread.setLine((_ref = (_ref1 = Unread.posts.first) != null ? _ref1.data : void 0, __indexOf.call(posts, _ref) >= 0)); } Unread.read(); return Unread.update(); @@ -9984,16 +9998,17 @@ } }, readSinglePost: function(post) { - var ID, i; + var ID, i, posts; ID = post.ID; - if (!Unread.posts[ID]) { + posts = Unread.posts; + if (!posts[ID]) { return; } - if (post === Unread.posts.first) { + if (post === posts.first) { Unread.lastReadPost = ID; Unread.saveLastReadPost(); } - Unread.posts.rm(ID); + posts.rm(ID); if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) { Unread.postsQuotingYou.splice(i, 1); } @@ -10017,10 +10032,10 @@ height = doc.clientHeight; posts = Unread.posts; while (post = posts.first) { - ID = post.ID, data = post.data; - if (!(Header.getBottomOf(data.nodes.root) > -1)) { + if (!(Header.getBottomOf(post.data.nodes.root) > -1)) { break; } + ID = post.ID, data = post.data; posts.rm(ID); if (Conf['Mark Quotes of You'] && QR.db.get({ boardID: data.board.ID, @@ -10060,8 +10075,8 @@ if (!(post = Unread.posts.first)) { return $.rm(Unread.hr); } - if ($.x('preceding-sibling::div[contains(@class,"replyContainer")]', post.nodes.root)) { - return $.before(post.nodes.root, Unread.hr); + if ($.x('preceding-sibling::div[contains(@class,"replyContainer")]', post.data.nodes.root)) { + return $.before(post.data.nodes.root, Unread.hr); } }, update: function(dontrepeat) { @@ -12081,7 +12096,7 @@ err = _error; error = [ { - message: "Quote Threading Failed.", + message: "" + name + " Failed.", error: err } ]; @@ -12312,7 +12327,8 @@ } Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Post, posts); - Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading']); + Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']); + Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']); Navigate.buildThread(); return Header.hashScroll.call(window); }, @@ -12322,7 +12338,6 @@ $.rmAll(board); $.add(board, [Navigate.threadRoot, $.el('hr')]); if (Conf['Unread Count']) { - Navigate.ready('Unread Count', Unread.ready, !Conf['Quote Threading']); Unread.read(); return Unread.update(); } diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 8e577e1c1..5b72b1882 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -375,25 +375,25 @@ Index = Main.callbackNodes Post, posts sort: -> + {liveThreadIDs, liveThreadData} = Index sortedThreadIDs = { lastreply: - [Index.liveThreadData...].sort((a, b) -> - a = a.last_replies[a.last_replies.length - 1] if 'last_replies' of a - b = b.last_replies[b.last_replies.length - 1] if 'last_replies' of b + [liveThreadData...].sort((a, b) -> + a = num[num.length - 1] if (num = a.last_replies) + b = num[num.length - 1] if (num = b.last_replies) b.no - a.no - ).map (data) -> data.no - bump: Index.liveThreadIDs - birth: [Index.liveThreadIDs... ].sort (a, b) -> b - a - replycount: [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies).map (data) -> data.no - filecount: [Index.liveThreadData...].sort((a, b) -> b.images - a.images ).map (data) -> data.no + ).map (post) -> post.no + bump: liveThreadIDs + birth: [liveThreadIDs... ].sort (a, b) -> b - a + replycount: [liveThreadData...].sort((a, b) -> b.replies - a.replies).map (post) -> post.no + filecount: [liveThreadData...].sort((a, b) -> b.images - a.images ).map (post) -> post.no }[Conf['Index Sort']] - Index.sortedNodes = new RandomAccessList + Index.sortedNodes = sortedNodes = new RandomAccessList {nodes} = Index for threadID in sortedThreadIDs - Index.sortedNodes.push nodes[Index.liveThreadIDs.indexOf(threadID)] + sortedNodes.push nodes[Index.liveThreadIDs.indexOf(threadID)] if Index.isSearching and nodes = Index.querySearch(Index.searchInput.value) - Index.sortedNodes = new RandomAccessList - Index.sortedNodes.push node for node in nodes + Index.sortedNodes = new RandomAccessList nodes items = [ # Sticky threads fn: (thread) -> thread.isSticky @@ -414,10 +414,10 @@ Index = sortOnTop: (match) -> offset = 0 {sortedNodes} = Index - threadRoot = Index.sortedNodes.first + threadRoot = sortedNodes.first while threadRoot if match Get.threadFromRoot threadRoot.data - target = Index.sortedNodes.first + target = sortedNodes.first j = 0 while j++ < offset target = target.next @@ -431,11 +431,9 @@ Index = if Conf['Index Mode'] isnt 'all pages' nodes = Index.buildSinglePage Index.getCurrentPage() else - nodes = [] - target = Index.sortedNodes.first - while target + nodes = [(target = Index.sortedNodes.first).data] + while target = target.next nodes.push target.data - target = target.next $.rmAll Index.root $.rmAll Header.hover Index.buildReplies nodes if Conf['Show Replies'] @@ -446,11 +444,10 @@ Index = nodesPerPage = Index.threadsNumPerPage offset = nodesPerPage * pageNum end = offset + nodesPerPage - target = Index.sortedNodes.first - i = 0 - while i <= end - if offset <= i++ - nodes.push target.data + target = Index.sortedNodes.order()[offset] + Index.sortedNodes + while (offset++ <= end) and target + nodes.push target.data target = target.next nodes @@ -501,7 +498,7 @@ Index = Index.search keywords search: (keywords) -> - found = [] + found = [] target = Index.sortedNodes.first while target {data} = target diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 56b17a4f3..8843d9a0c 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -83,7 +83,7 @@ Navigate = feature() if condition catch err error = [ - message: "Quote Threading Failed." + message: "#{name} Failed." error: err ] Main.handleErrors error if error @@ -284,7 +284,8 @@ Navigate = Main.callbackNodes Thread, [thread] Main.callbackNodes Post, posts - Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading'] + Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading'] and not Conf['Unread Count'] + Navigate.ready 'Unread Count', Unread.ready, Conf['Unread Count'] Navigate.buildThread() Header.hashScroll.call window @@ -295,7 +296,6 @@ Navigate = $.add board, [Navigate.threadRoot, $.el 'hr'] if Conf['Unread Count'] - Navigate.ready 'Unread Count', Unread.ready, not Conf['Quote Threading'] Unread.read() Unread.update() diff --git a/src/General/lib/randomaccesslist.class b/src/General/lib/randomaccesslist.class index 9ccbfeb43..b161177b4 100644 --- a/src/General/lib/randomaccesslist.class +++ b/src/General/lib/randomaccesslist.class @@ -1,6 +1,7 @@ class RandomAccessList - constructor: -> + constructor: (items) -> @length = 0 + @push item for item in items if items push: (data) -> {ID} = data @@ -52,6 +53,11 @@ class RandomAccessList shift: -> @rm @first.ID + + order: -> + order = [item = @first] + order.push item while item = item.next + order rm: (ID) -> item = @[ID] diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 56a610731..6b5989a68 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -52,7 +52,7 @@ Unread = return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts if post = Unread.posts.first # Scroll to a non-hidden, non-OP post that's before the first unread post. - while root = $.x 'preceding-sibling::div[contains(@class,"replyContainer")][1]', post.nodes.root + while root = $.x 'preceding-sibling::div[contains(@class,"replyContainer")][1]', post.data.nodes.root break unless (post = Get.postFromRoot root).isHidden return unless root down = true @@ -95,7 +95,7 @@ Unread = Unread.addPostQuotingYou post if Conf['Unread Line'] # Force line on visible threads if there were no unread posts previously. - Unread.setLine Unread.posts.first.data in posts + Unread.setLine Unread.posts.first?.data in posts Unread.read() Unread.update() @@ -131,11 +131,12 @@ Unread = readSinglePost: (post) -> {ID} = post - return unless Unread.posts[ID] - if post is Unread.posts.first + {posts} = Unread + return unless posts[ID] + if post is posts.first Unread.lastReadPost = ID Unread.saveLastReadPost() - Unread.posts.rm ID + posts.rm ID if (i = Unread.postsQuotingYou.indexOf post) isnt -1 Unread.postsQuotingYou.splice i, 1 Unread.update() @@ -151,8 +152,8 @@ Unread = {posts} = Unread while post = posts.first + break unless Header.getBottomOf(post.data.nodes.root) > -1 # post is not completely read {ID, data} = post - break unless Header.getBottomOf(data.nodes.root) > -1 # post is not completely read posts.rm ID if Conf['Mark Quotes of You'] and QR.db.get { @@ -179,8 +180,8 @@ Unread = setLine: (force) -> return unless d.hidden or force is true return $.rm Unread.hr unless post = Unread.posts.first - if $.x 'preceding-sibling::div[contains(@class,"replyContainer")]', post.nodes.root # not the first reply - $.before post.nodes.root, Unread.hr + if $.x 'preceding-sibling::div[contains(@class,"replyContainer")]', post.data.nodes.root # not the first reply + $.before post.data.nodes.root, Unread.hr update: <% if (type === 'crx') { %>(dontrepeat) <% } %>-> count = Unread.posts.length diff --git a/src/Quotelinks/QuoteThreading.coffee b/src/Quotelinks/QuoteThreading.coffee index 077dde1e7..7b77a13a3 100755 --- a/src/Quotelinks/QuoteThreading.coffee +++ b/src/Quotelinks/QuoteThreading.coffee @@ -45,12 +45,16 @@ QuoteThreading = g.posts.forEach (post) -> post.cb true if post.cb + if Conf['Unread Count'] and Unread.thread.OP.nodes.root.parentElement.parentElement + Unread.read() + Unread.update() + node: -> {posts} = g return if @isClone or not QuoteThreading.enabled - Unread.posts.push @ if Conf['Unread Count'] - return if @thread.OP is @ or !(post = posts[@fullID]) or post.isHidden # Filtered + Unread.posts.push @ if Conf['Unread Count'] + return if @thread.OP is @ or @isHidden # Filtered keys = [] len = g.BOARD.ID.length + 1 @@ -90,11 +94,11 @@ QuoteThreading = return true unless Conf['Unread Count'] - if posts[post.ID] - posts.after post, @ + if post = posts[post.ID] + posts.after post, posts[@ID] else - posts.prepend @ + posts.prepend posts[@ID] return true