diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 5d5a7ed69..2e3f25f91 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -1480,21 +1480,19 @@ } this.rmi(item); next = root.next; - root.next = next.prev = item; + root.next = item; + item.prev = root; item.next = next; - return item.prev = root; + return next.prev = item; }; RandomAccessList.prototype.prepend = function(item) { - var ID, first; - ID = item.ID; - if (!this[ID]) { - this.push(item); - } + var first; first = this.first; - if (item === first) { + if (item === first || !this[item.ID]) { return; } + this.rmi(item); item.next = first; first.prev = item; this.first = item; @@ -1505,22 +1503,6 @@ return this.rm(this.first.ID); }; - RandomAccessList.prototype.splice = function(start, end) { - var cur, next; - if (!this[end]) { - return; - } - cur = start === 0 ? this.first : this[start]; - while (cur) { - next = cur.next; - this.rm(cur.ID); - if (!next || cur.ID === end) { - return; - } - cur = next; - } - }; - RandomAccessList.prototype.rm = function(ID) { var item; item = this[ID]; @@ -1554,7 +1536,7 @@ item = this.first; while (item) { if (item.ID > ID) { - prev = item.prev.prev; + prev = item.prev; break; } item = item.next; @@ -4979,12 +4961,21 @@ }, node: function() { var ID, fullID, keys, len, post, posts, quote, quotes, _i, _len; - if (this.isClone || !QuoteThreading.enabled || this.thread.OP === this) { + if (this.isClone || !QuoteThreading.enabled) { + return; + } + if (this.thread.OP === this) { + if (Conf['Unread Count']) { + Unread.posts.push(this); + } return; } quotes = this.quotes, ID = this.ID, fullID = this.fullID; posts = g.posts; if (!(post = posts[fullID]) || post.isHidden) { + if (Conf['Unread Count']) { + Unread.posts.push(this); + } return; } keys = []; @@ -4998,6 +4989,9 @@ } } if (keys.length !== 1) { + if (Conf['Unread Count']) { + Unread.posts.push(this); + } return; } this.threaded = keys[0]; @@ -5008,12 +5002,18 @@ post = g.posts[this.threaded]; posts = Unread.posts; if (this.thread.OP === post) { + if (Conf['Unread Count']) { + posts.push(this); + } return false; } if (QuoteThreading.hasRun) { height = doc.clientHeight; _ref = post.nodes.root.getBoundingClientRect(), bottom = _ref.bottom, top = _ref.top; if (!((posts != null ? posts[post.ID] : void 0) || ((bottom < height) && (top > 0)))) { + if (Conf['Unread Count']) { + posts.push(this); + } return false; } } @@ -5026,9 +5026,11 @@ $.after(root, threadContainer); } else { threadContainer = root.nextSibling; + post = Get.postFromRoot($.x('child::div[contains(@class,"postContainer")][last()]', threadContainer)); } $.add(threadContainer, this.nodes.root); if (!Conf['Unread Count'] || this.ID < Unread.lastReadPost) { + this.prev = true; return true; } if (!posts[this.ID]) { @@ -5037,7 +5039,7 @@ if (posts[post.ID]) { posts.after(post, this); } else { - if ((ID = posts.closest(ID)) !== -1) { + if ((ID = posts.closest(post.ID)) !== -1) { posts.after(posts[ID], this); } else { posts.prepend(this); @@ -9699,11 +9701,11 @@ if (!Unread.posts[ID]) { return; } - Unread.posts.rm(ID); if (post === Unread.posts.first) { Unread.lastReadPost = ID; Unread.saveLastReadPost(); } + Unread.posts.rm(ID); if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) { Unread.postsQuotingYou.splice(i, 1); } diff --git a/builds/crx/script.js b/builds/crx/script.js index b18addccd..8279e6a60 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1486,21 +1486,19 @@ } this.rmi(item); next = root.next; - root.next = next.prev = item; + root.next = item; + item.prev = root; item.next = next; - return item.prev = root; + return next.prev = item; }; RandomAccessList.prototype.prepend = function(item) { - var ID, first; - ID = item.ID; - if (!this[ID]) { - this.push(item); - } + var first; first = this.first; - if (item === first) { + if (item === first || !this[item.ID]) { return; } + this.rmi(item); item.next = first; first.prev = item; this.first = item; @@ -1511,22 +1509,6 @@ return this.rm(this.first.ID); }; - RandomAccessList.prototype.splice = function(start, end) { - var cur, next; - if (!this[end]) { - return; - } - cur = start === 0 ? this.first : this[start]; - while (cur) { - next = cur.next; - this.rm(cur.ID); - if (!next || cur.ID === end) { - return; - } - cur = next; - } - }; - RandomAccessList.prototype.rm = function(ID) { var item; item = this[ID]; @@ -1560,7 +1542,7 @@ item = this.first; while (item) { if (item.ID > ID) { - prev = item.prev.prev; + prev = item.prev; break; } item = item.next; @@ -4982,12 +4964,21 @@ }, node: function() { var ID, fullID, keys, len, post, posts, quote, quotes, _i, _len; - if (this.isClone || !QuoteThreading.enabled || this.thread.OP === this) { + if (this.isClone || !QuoteThreading.enabled) { + return; + } + if (this.thread.OP === this) { + if (Conf['Unread Count']) { + Unread.posts.push(this); + } return; } quotes = this.quotes, ID = this.ID, fullID = this.fullID; posts = g.posts; if (!(post = posts[fullID]) || post.isHidden) { + if (Conf['Unread Count']) { + Unread.posts.push(this); + } return; } keys = []; @@ -5001,6 +4992,9 @@ } } if (keys.length !== 1) { + if (Conf['Unread Count']) { + Unread.posts.push(this); + } return; } this.threaded = keys[0]; @@ -5011,12 +5005,18 @@ post = g.posts[this.threaded]; posts = Unread.posts; if (this.thread.OP === post) { + if (Conf['Unread Count']) { + posts.push(this); + } return false; } if (QuoteThreading.hasRun) { height = doc.clientHeight; _ref = post.nodes.root.getBoundingClientRect(), bottom = _ref.bottom, top = _ref.top; if (!((posts != null ? posts[post.ID] : void 0) || ((bottom < height) && (top > 0)))) { + if (Conf['Unread Count']) { + posts.push(this); + } return false; } } @@ -5029,9 +5029,11 @@ $.after(root, threadContainer); } else { threadContainer = root.nextSibling; + post = Get.postFromRoot($.x('child::div[contains(@class,"postContainer")][last()]', threadContainer)); } $.add(threadContainer, this.nodes.root); if (!Conf['Unread Count'] || this.ID < Unread.lastReadPost) { + this.prev = true; return true; } if (!posts[this.ID]) { @@ -5040,7 +5042,7 @@ if (posts[post.ID]) { posts.after(post, this); } else { - if ((ID = posts.closest(ID)) !== -1) { + if ((ID = posts.closest(post.ID)) !== -1) { posts.after(posts[ID], this); } else { posts.prepend(this); @@ -9682,11 +9684,11 @@ if (!Unread.posts[ID]) { return; } - Unread.posts.rm(ID); if (post === Unread.posts.first) { Unread.lastReadPost = ID; Unread.saveLastReadPost(); } + Unread.posts.rm(ID); if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) { Unread.postsQuotingYou.splice(i, 1); } diff --git a/src/General/lib/randomaccesslist.class b/src/General/lib/randomaccesslist.class index a2907aa01..a9955ff62 100644 --- a/src/General/lib/randomaccesslist.class +++ b/src/General/lib/randomaccesslist.class @@ -19,16 +19,16 @@ class RandomAccessList @rmi item {next} = root - root.next = next.prev = item - item.next = next + root.next = item item.prev = root + item.next = next + next.prev = item prepend: (item) -> - {ID} = item - @push item unless @[ID] {first} = @ - return if item is first - item.next = first + return if item is first or not @[item.ID] + @rmi item + item.next = first first.prev = item @first = item delete item.prev @@ -36,15 +36,6 @@ class RandomAccessList shift: -> @rm @first.ID - splice: (start, end) -> - return unless @[end] - cur = if start is 0 then @first else @[start] - while cur - {next} = cur - @rm cur.ID - return if not next or cur.ID is end - cur = next - rm: (ID) -> item = @[ID] return unless item @@ -69,7 +60,7 @@ class RandomAccessList item = @first while item if item.ID > ID - {prev} = item.prev + {prev} = item break item = item.next return (if prev then prev.ID else -1) \ No newline at end of file diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 52789e67d..146578b67 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -122,10 +122,10 @@ Unread = readSinglePost: (post) -> {ID} = post return unless Unread.posts[ID] - Unread.posts.rm ID if post is Unread.posts.first Unread.lastReadPost = ID Unread.saveLastReadPost() + Unread.posts.rm ID if (i = Unread.postsQuotingYou.indexOf post) isnt -1 Unread.postsQuotingYou.splice i, 1 Unread.update() diff --git a/src/Quotelinks/QuoteThreading.coffee b/src/Quotelinks/QuoteThreading.coffee index eacb9b753..6b2c5bbcd 100755 --- a/src/Quotelinks/QuoteThreading.coffee +++ b/src/Quotelinks/QuoteThreading.coffee @@ -32,18 +32,25 @@ QuoteThreading = QuoteThreading.hasRun = true node: -> - return if @isClone or not QuoteThreading.enabled or @thread.OP is @ + return if @isClone or not QuoteThreading.enabled + if @thread.OP is @ + Unread.posts.push @ if Conf['Unread Count'] + return {quotes, ID, fullID} = @ {posts} = g - return if !(post = posts[fullID]) or post.isHidden # Filtered + if !(post = posts[fullID]) or post.isHidden # Filtered + Unread.posts.push @ if Conf['Unread Count'] + return keys = [] len = "#{g.BOARD}".length + 1 for quote in quotes when quote[len..] < ID keys.push quote if quote of posts - return unless keys.length is 1 + unless keys.length is 1 + Unread.posts.push @ if Conf['Unread Count'] + return @threaded = keys[0] @cb = QuoteThreading.nodeinsert @@ -52,14 +59,18 @@ QuoteThreading = post = g.posts[@threaded] {posts} = Unread - return false if @thread.OP is post + if @thread.OP is post + posts.push @ if Conf['Unread Count'] + return false if QuoteThreading.hasRun height = doc.clientHeight {bottom, top} = post.nodes.root.getBoundingClientRect() # Post is unread or is fully visible. - return false unless posts?[post.ID] or ((bottom < height) and (top > 0)) + unless posts?[post.ID] or ((bottom < height) and (top > 0)) + posts.push @ if Conf['Unread Count'] + return false root = post.nodes.root unless $.hasClass root, 'threadOP' @@ -69,17 +80,20 @@ QuoteThreading = $.after root, threadContainer else threadContainer = root.nextSibling + post = Get.postFromRoot $.x 'child::div[contains(@class,"postContainer")][last()]', threadContainer $.add threadContainer, @nodes.root - return true if not Conf['Unread Count'] or @ID < Unread.lastReadPost + if not Conf['Unread Count'] or @ID < Unread.lastReadPost + @prev = true # Force Unread Count to ignore this post + return true posts.push @ unless posts[@ID] if posts[post.ID] posts.after post, @ else - if (ID = posts.closest ID) isnt -1 + if (ID = posts.closest post.ID) isnt -1 posts.after posts[ID], @ else posts.prepend @