From 77d97277c95bc5204457f0f2772237a4c8bce709 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 6 Jan 2014 09:04:45 -0700 Subject: [PATCH] Minor optimizations --- builds/4chan-X.user.js | 30 ++++++++++------------------ builds/crx/script.js | 30 ++++++++++------------------ src/Quotelinks/QuoteThreading.coffee | 20 +++++++------------ 3 files changed, 29 insertions(+), 51 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 130f342a8..d1af9a85a 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4936,14 +4936,14 @@ innerHTML: '' }); input = $('input', this.controls); - $.on(input, 'change', QuoteThreading.toggle); + $.on(input, 'change', this.toggle); $.event('AddMenuEntry', { type: 'header', el: this.controls, order: 98 }); if (!Conf['Unread Count']) { - $.on(d, '4chanXInitFinished', QuoteThreading.setup); + $.on(d, '4chanXInitFinished', this.setup); } return Post.callbacks.push({ name: 'Quote Threading', @@ -4963,35 +4963,27 @@ return QuoteThreading.hasRun = true; }, node: function() { - var ID, fullID, keys, len, post, posts, quote, quotes, _i, _len; + var keys, len, post, posts, quote, _i, _len, _ref; + posts = g.posts; if (this.isClone || !QuoteThreading.enabled) { return; } if (Conf['Unread Count']) { Unread.posts.push(this); } - if (this.thread.OP === this) { - return; - } - quotes = this.quotes, ID = this.ID, fullID = this.fullID; - posts = g.posts; - if (!(post = posts[fullID]) || post.isHidden) { + if (this.thread.OP === this || !(post = posts[this.fullID]) || post.isHidden) { return; } keys = []; - len = ("" + g.BOARD).length + 1; - for (_i = 0, _len = quotes.length; _i < _len; _i++) { - quote = quotes[_i]; - if (quote.slice(len) < ID) { - if (quote in posts) { - keys.push(quote); - } + len = g.BOARD.ID.length + 1; + _ref = this.quotes; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + quote = _ref[_i]; + if ((quote.slice(len) < this.ID) && quote in posts) { + keys.push(quote); } } if (keys.length !== 1) { - if (Conf['Unread Count']) { - Unread.posts.push(this); - } return; } this.threaded = keys[0]; diff --git a/builds/crx/script.js b/builds/crx/script.js index 270b77c00..41ea48332 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4939,14 +4939,14 @@ innerHTML: '' }); input = $('input', this.controls); - $.on(input, 'change', QuoteThreading.toggle); + $.on(input, 'change', this.toggle); $.event('AddMenuEntry', { type: 'header', el: this.controls, order: 98 }); if (!Conf['Unread Count']) { - $.on(d, '4chanXInitFinished', QuoteThreading.setup); + $.on(d, '4chanXInitFinished', this.setup); } return Post.callbacks.push({ name: 'Quote Threading', @@ -4966,35 +4966,27 @@ return QuoteThreading.hasRun = true; }, node: function() { - var ID, fullID, keys, len, post, posts, quote, quotes, _i, _len; + var keys, len, post, posts, quote, _i, _len, _ref; + posts = g.posts; if (this.isClone || !QuoteThreading.enabled) { return; } if (Conf['Unread Count']) { Unread.posts.push(this); } - if (this.thread.OP === this) { - return; - } - quotes = this.quotes, ID = this.ID, fullID = this.fullID; - posts = g.posts; - if (!(post = posts[fullID]) || post.isHidden) { + if (this.thread.OP === this || !(post = posts[this.fullID]) || post.isHidden) { return; } keys = []; - len = ("" + g.BOARD).length + 1; - for (_i = 0, _len = quotes.length; _i < _len; _i++) { - quote = quotes[_i]; - if (quote.slice(len) < ID) { - if (quote in posts) { - keys.push(quote); - } + len = g.BOARD.ID.length + 1; + _ref = this.quotes; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + quote = _ref[_i]; + if ((quote.slice(len) < this.ID) && quote in posts) { + keys.push(quote); } } if (keys.length !== 1) { - if (Conf['Unread Count']) { - Unread.posts.push(this); - } return; } this.threaded = keys[0]; diff --git a/src/Quotelinks/QuoteThreading.coffee b/src/Quotelinks/QuoteThreading.coffee index 1d25944d5..d5901b402 100755 --- a/src/Quotelinks/QuoteThreading.coffee +++ b/src/Quotelinks/QuoteThreading.coffee @@ -11,14 +11,14 @@ QuoteThreading = innerHTML: '' input = $ 'input', @controls - $.on input, 'change', QuoteThreading.toggle + $.on input, 'change', @toggle $.event 'AddMenuEntry', type: 'header' el: @controls order: 98 - $.on d, '4chanXInitFinished', QuoteThreading.setup unless Conf['Unread Count'] + $.on d, '4chanXInitFinished', @setup unless Conf['Unread Count'] Post.callbacks.push name: 'Quote Threading' @@ -32,23 +32,17 @@ QuoteThreading = QuoteThreading.hasRun = true node: -> + {posts} = g return if @isClone or not QuoteThreading.enabled Unread.posts.push @ if Conf['Unread Count'] - return if @thread.OP is @ - - {quotes, ID, fullID} = @ - {posts} = g - return if !(post = posts[fullID]) or post.isHidden # Filtered + return if @thread.OP is @ or !(post = posts[@fullID]) or post.isHidden # Filtered keys = [] - len = "#{g.BOARD}".length + 1 - for quote in quotes when quote[len..] < ID - keys.push quote if quote of posts + len = g.BOARD.ID.length + 1 + keys.push quote for quote in @quotes when (quote[len..] < @ID) and quote of posts - unless keys.length is 1 - Unread.posts.push @ if Conf['Unread Count'] - return + return unless keys.length is 1 @threaded = keys[0] @cb = QuoteThreading.nodeinsert