From e451410ef16e438ee63debfa193fa7e027d111b4 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 2 Mar 2014 19:45:54 -0700 Subject: [PATCH] Small reflow to QuoteBacklink I. I don't like concatenating for temporary data. --- builds/4chan-X.user.js | 16 +++++++++++----- builds/crx/script.js | 16 +++++++++++----- src/General/Navigate.coffee | 3 +-- src/Quotelinks/QuoteBacklink.coffee | 14 +++++++++++--- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index e3b85c7de..c3f7e7b41 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -5185,21 +5185,25 @@ }); }, firstNode: function() { - var container, post, quoteID, _base, _i, _j, _len, _len1, _ref, _ref1; + var addNodes, container, post, quoteID, _base, _i, _j, _len, _len1, _ref, _ref1; if (this.isClone) { return; } + addNodes = function(post, that) { + return $.add(post.nodes.backlinkContainer, QuoteBacklink.buildBacklink(post, that)); + }; _ref = this.quotes; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quoteID = _ref[_i]; ((_base = QuoteBacklink.map)[quoteID] || (_base[quoteID] = [])).push(this.fullID); - if (!((post = g.posts[quoteID]) && (container = post != null ? post.nodes.backlinkContainer : void 0))) { + if (!(((post = g.posts[quoteID]) != null) && (container = post.nodes.backlinkContainer))) { continue; } - _ref1 = [post].concat(post.clones); + addNodes(post, this); + _ref1 = post.clones; for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { post = _ref1[_j]; - $.add(post.nodes.backlinkContainer, QuoteBacklink.buildBacklink(post, this)); + addNodes(post, this); } } }, @@ -12566,7 +12570,9 @@ g.threads.forEach(function(thread) { return thread.collect(); }); - QuoteBacklink.containers = {}; + if (Conf['Quote Backlinks']) { + QuoteBacklink.map = {}; + } return $.rmAll($('.board')); }, features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]], diff --git a/builds/crx/script.js b/builds/crx/script.js index 0d4218ca1..e20d47654 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -5237,21 +5237,25 @@ }); }, firstNode: function() { - var container, post, quoteID, _base, _i, _j, _len, _len1, _ref, _ref1; + var addNodes, container, post, quoteID, _base, _i, _j, _len, _len1, _ref, _ref1; if (this.isClone) { return; } + addNodes = function(post, that) { + return $.add(post.nodes.backlinkContainer, QuoteBacklink.buildBacklink(post, that)); + }; _ref = this.quotes; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quoteID = _ref[_i]; ((_base = QuoteBacklink.map)[quoteID] || (_base[quoteID] = [])).push(this.fullID); - if (!((post = g.posts[quoteID]) && (container = post != null ? post.nodes.backlinkContainer : void 0))) { + if (!(((post = g.posts[quoteID]) != null) && (container = post.nodes.backlinkContainer))) { continue; } - _ref1 = [post].concat(post.clones); + addNodes(post, this); + _ref1 = post.clones; for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { post = _ref1[_j]; - $.add(post.nodes.backlinkContainer, QuoteBacklink.buildBacklink(post, this)); + addNodes(post, this); } } }, @@ -12580,7 +12584,9 @@ g.threads.forEach(function(thread) { return thread.collect(); }); - QuoteBacklink.containers = {}; + if (Conf['Quote Backlinks']) { + QuoteBacklink.map = {}; + } return $.rmAll($('.board')); }, features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]], diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 3cdaf56c2..df5c8eb72 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -36,8 +36,7 @@ Navigate = clean: -> # Garbage collection g.threads.forEach (thread) -> thread.collect() - QuoteBacklink.containers = {} - + QuoteBacklink.map = {} if Conf['Quote Backlinks'] # Containers can get pretty icky. $.rmAll $ '.board' features: [ diff --git a/src/Quotelinks/QuoteBacklink.coffee b/src/Quotelinks/QuoteBacklink.coffee index f04c0a555..fffde3e2c 100755 --- a/src/Quotelinks/QuoteBacklink.coffee +++ b/src/Quotelinks/QuoteBacklink.coffee @@ -16,20 +16,27 @@ QuoteBacklink = @funk = Function 'id', "return '#{format}'" @frag = $.nodes [$.tn(' '), $.el 'a', className: 'backlink'] @map = {} + Post.callbacks.push name: 'Quote Backlinking Part 1' cb: @firstNode + Post.callbacks.push name: 'Quote Backlinking Part 2' cb: @secondNode + firstNode: -> return if @isClone + addNodes = (post, that) -> + $.add post.nodes.backlinkContainer, QuoteBacklink.buildBacklink post, that for quoteID in @quotes (QuoteBacklink.map[quoteID] or= []).push @fullID - continue unless (post = g.posts[quoteID]) and container = post?.nodes.backlinkContainer - for post in [post].concat post.clones - $.add post.nodes.backlinkContainer, QuoteBacklink.buildBacklink post, @ + continue unless (post = g.posts[quoteID])? and container = post.nodes.backlinkContainer + addNodes post, @ + for post in post.clones + addNodes post, @ return + secondNode: -> # Don't backlink the OP. return unless @isReply or Conf['OP Backlinks'] @@ -46,6 +53,7 @@ QuoteBacklink = if post = g.posts[quoteID] # Post hasn't been collected since. $.add container, QuoteBacklink.buildBacklink @, post $.add @nodes.info, container + buildBacklink: (quoted, quoter) -> frag = QuoteBacklink.frag.cloneNode true a = frag.lastElementChild