From ce6e317c98c7de912b614b4db877e237fa55f580 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Wed, 7 Aug 2013 20:55:23 -0700 Subject: [PATCH] Time to stop being silly. --- builds/4chan-X.user.js | 53 +++++++++-------------------- builds/crx/script.js | 53 +++++++++-------------------- src/General/lib/$.coffee | 18 ---------- src/Monitoring/Unread.coffee | 19 ++++++++--- src/Quotelinks/QuoteBacklink.coffee | 2 +- 5 files changed, 49 insertions(+), 96 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 41c542a2f..373cd2533 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -336,15 +336,6 @@ return this.indexOf(string) > -1; }; - Array.prototype.add = function(object, position) { - var keep; - - keep = this.slice(position); - this.length = position; - this.push(object); - return this.pushArrays(keep); - }; - Array.prototype.contains = function(object) { return this.indexOf(object) > -1; }; @@ -361,27 +352,6 @@ return i; }; - Array.prototype.pushArrays = function() { - var arg, args, _i, _len; - - args = arguments; - for (_i = 0, _len = args.length; _i < _len; _i++) { - arg = args[_i]; - this.push.apply(this, arg); - } - return this; - }; - - Array.prototype.remove = function(object) { - var index; - - if ((index = this.indexOf(object)) > -1) { - return this.splice(index, 1); - } else { - return false; - } - }; - $ = function(selector, root) { if (root == null) { root = d.body; @@ -3683,7 +3653,7 @@ if (Conf['Quote Inlining']) { $.on(link, 'click', QuoteInline.toggle); if (Conf['Quote Hash Navigation']) { - frag.pushArrays(QuoteInline.qiQuote(link, $.hasClass(link, 'filtered'))); + frag.push.apply(frag, QuoteInline.qiQuote(link, $.hasClass(link, 'filtered'))); } } $.add(container, frag); @@ -7992,17 +7962,28 @@ height = doc.clientHeight; posts = Unread.posts; i = 0; - while (post = posts[i++]) { + while (post = posts[i]) { bottom = post.nodes.root.getBoundingClientRect().bottom; - if (bottom < height) { - ID = post.ID; - posts.remove(post); + if (bottom > height) { + i++; + continue; } + ID = post.ID; + if (Conf['Quote Threading']) { + posts.splice(i, 1); + continue; + } else { + posts.splice(0, i); + break; + } + i++; } if (!ID) { return; } - Unread.lastReadPost = ID; + if (Unread.lastReadPost < ID || !Unread.lastReadPost) { + Unread.lastReadPost = ID; + } Unread.saveLastReadPost(); Unread.readArray(Unread.postsQuotingYou); return Unread.update(); diff --git a/builds/crx/script.js b/builds/crx/script.js index e88002f09..304eb227a 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -317,15 +317,6 @@ return this.indexOf(string) > -1; }; - Array.prototype.add = function(object, position) { - var keep; - - keep = this.slice(position); - this.length = position; - this.push(object); - return this.pushArrays(keep); - }; - Array.prototype.contains = function(object) { return this.indexOf(object) > -1; }; @@ -342,27 +333,6 @@ return i; }; - Array.prototype.pushArrays = function() { - var arg, args, _i, _len; - - args = arguments; - for (_i = 0, _len = args.length; _i < _len; _i++) { - arg = args[_i]; - this.push.apply(this, arg); - } - return this; - }; - - Array.prototype.remove = function(object) { - var index; - - if ((index = this.indexOf(object)) > -1) { - return this.splice(index, 1); - } else { - return false; - } - }; - $ = function(selector, root) { if (root == null) { root = d.body; @@ -3688,7 +3658,7 @@ if (Conf['Quote Inlining']) { $.on(link, 'click', QuoteInline.toggle); if (Conf['Quote Hash Navigation']) { - frag.pushArrays(QuoteInline.qiQuote(link, $.hasClass(link, 'filtered'))); + frag.push.apply(frag, QuoteInline.qiQuote(link, $.hasClass(link, 'filtered'))); } } $.add(container, frag); @@ -7973,17 +7943,28 @@ height = doc.clientHeight; posts = Unread.posts; i = 0; - while (post = posts[i++]) { + while (post = posts[i]) { bottom = post.nodes.root.getBoundingClientRect().bottom; - if (bottom < height) { - ID = post.ID; - posts.remove(post); + if (bottom > height) { + i++; + continue; } + ID = post.ID; + if (Conf['Quote Threading']) { + posts.splice(i, 1); + continue; + } else { + posts.splice(0, i); + break; + } + i++; } if (!ID) { return; } - Unread.lastReadPost = ID; + if (Unread.lastReadPost < ID || !Unread.lastReadPost) { + Unread.lastReadPost = ID; + } Unread.saveLastReadPost(); Unread.readArray(Unread.postsQuotingYou); return Unread.update(); diff --git a/src/General/lib/$.coffee b/src/General/lib/$.coffee index 1569f960e..34a0e8af7 100644 --- a/src/General/lib/$.coffee +++ b/src/General/lib/$.coffee @@ -4,12 +4,6 @@ String::capitalize = -> String::contains = (string) -> @indexOf(string) > -1 -Array::add = (object, position) -> - keep = @slice position - @length = position - @push object - @pushArrays keep - Array::contains = (object) -> @indexOf(object) > -1 @@ -19,18 +13,6 @@ Array::indexOf = (object) -> return i if @[i] is object return i -Array::pushArrays = -> - args = arguments - for arg in args - @push.apply @, arg - return @ - -Array::remove = (object) -> - if (index = @indexOf object) > -1 - @splice index, 1 - else - false - # loosely follows the jquery api: # http://api.jquery.com/ # not chainable diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 1979f3bbb..788b41753 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -121,14 +121,23 @@ Unread = {posts} = Unread i = 0 - while post = posts[i++] + while post = posts[i] {bottom} = post.nodes.root.getBoundingClientRect() - if (bottom < height) # post is completely read - {ID} = post - posts.remove post + if bottom > height # post isnt completely read + i++ + continue + + {ID} = post + if Conf['Quote Threading'] + posts.splice i, 1 + continue + else + posts.splice 0, i + break + i++ return unless ID - Unread.lastReadPost = ID + Unread.lastReadPost = ID if Unread.lastReadPost < ID or !Unread.lastReadPost Unread.saveLastReadPost() Unread.readArray Unread.postsQuotingYou Unread.update() diff --git a/src/Quotelinks/QuoteBacklink.coffee b/src/Quotelinks/QuoteBacklink.coffee index 91bbb6e84..ae4a4b433 100644 --- a/src/Quotelinks/QuoteBacklink.coffee +++ b/src/Quotelinks/QuoteBacklink.coffee @@ -41,7 +41,7 @@ QuoteBacklink = $.on link, 'mouseover', QuotePreview.mouseover if Conf['Quote Inlining'] $.on link, 'click', QuoteInline.toggle - frag.pushArrays QuoteInline.qiQuote link, $.hasClass link, 'filtered' if Conf['Quote Hash Navigation'] + frag.push.apply frag, QuoteInline.qiQuote link, $.hasClass link, 'filtered' if Conf['Quote Hash Navigation'] $.add container, frag return secondNode: ->