From 56c7288d8d3a40829c7d8c414f5a7bae5e5ea8b5 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 13 Jan 2014 00:44:20 -0700 Subject: [PATCH] [].push.appy and [].concat? Lets... comprehend that code better. --- builds/4chan-X.user.js | 41 ++++++++++++++++++++++++----------------- builds/crx/script.js | 41 ++++++++++++++++++++++++----------------- src/General/Get.coffee | 16 ++++++++++------ 3 files changed, 58 insertions(+), 40 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index bf2a32a0b..4980dd4ad 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -3108,36 +3108,43 @@ }; }, allQuotelinksLinkingTo: function(post) { - var ID, quote, quotedPost, quotelinks, quoterPost, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _ref4; + var ID, handleClones, qLconcat, quote, quotedPost, quotelinks, quoterPost, _i, _len, _ref, _ref1, _ref2; quotelinks = []; + qLconcat = function(links) { + return quotelinks = quotelinks.concat(links); + }; + handleClones = function(clones) { + var clone, _i, _len, _results; + _results = []; + for (_i = 0, _len = clones.length; _i < _len; _i++) { + clone = clones[_i]; + _results.push(qLconcat(clone.nodes.quotelinks)); + } + return _results; + }; _ref = g.posts; for (ID in _ref) { quoterPost = _ref[ID]; - if (_ref1 = post.fullID, __indexOf.call(quoterPost.quotes, _ref1) >= 0) { - _ref2 = [quoterPost].concat(quoterPost.clones); - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - quoterPost = _ref2[_i]; - quotelinks.push.apply(quotelinks, quoterPost.nodes.quotelinks); - } + if (!(_ref1 = post.fullID, __indexOf.call(quoterPost.quotes, _ref1) >= 0)) { + continue; } + qLconcat(quoterPost.nodes.quotelinks); + handleClones(quoterPost.clones); } if (Conf['Quote Backlinks']) { - _ref3 = post.quotes; - for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { - quote = _ref3[_j]; + _ref2 = post.quotes; + for (_i = 0, _len = _ref2.length; _i < _len; _i++) { + quote = _ref2[_i]; if (!(quotedPost = g.posts[quote])) { continue; } - _ref4 = [quotedPost].concat(quotedPost.clones); - for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) { - quotedPost = _ref4[_k]; - quotelinks.push.apply(quotelinks, __slice.call(quotedPost.nodes.backlinks)); - } + qLconcat(quotedPost.nodes.quotelinks); + handleClones(quotedPost.clones); } } return quotelinks.filter(function(quotelink) { - var boardID, postID, _ref5; - _ref5 = Get.postDataFromLink(quotelink), boardID = _ref5.boardID, postID = _ref5.postID; + var boardID, postID, _ref3; + _ref3 = Get.postDataFromLink(quotelink), boardID = _ref3.boardID, postID = _ref3.postID; return boardID === post.board.ID && postID === post.ID; }); }, diff --git a/builds/crx/script.js b/builds/crx/script.js index c1f08f65c..dd80003ec 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -3118,36 +3118,43 @@ }; }, allQuotelinksLinkingTo: function(post) { - var ID, quote, quotedPost, quotelinks, quoterPost, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _ref4; + var ID, handleClones, qLconcat, quote, quotedPost, quotelinks, quoterPost, _i, _len, _ref, _ref1, _ref2; quotelinks = []; + qLconcat = function(links) { + return quotelinks = quotelinks.concat(links); + }; + handleClones = function(clones) { + var clone, _i, _len, _results; + _results = []; + for (_i = 0, _len = clones.length; _i < _len; _i++) { + clone = clones[_i]; + _results.push(qLconcat(clone.nodes.quotelinks)); + } + return _results; + }; _ref = g.posts; for (ID in _ref) { quoterPost = _ref[ID]; - if (_ref1 = post.fullID, __indexOf.call(quoterPost.quotes, _ref1) >= 0) { - _ref2 = [quoterPost].concat(quoterPost.clones); - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - quoterPost = _ref2[_i]; - quotelinks.push.apply(quotelinks, quoterPost.nodes.quotelinks); - } + if (!(_ref1 = post.fullID, __indexOf.call(quoterPost.quotes, _ref1) >= 0)) { + continue; } + qLconcat(quoterPost.nodes.quotelinks); + handleClones(quoterPost.clones); } if (Conf['Quote Backlinks']) { - _ref3 = post.quotes; - for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { - quote = _ref3[_j]; + _ref2 = post.quotes; + for (_i = 0, _len = _ref2.length; _i < _len; _i++) { + quote = _ref2[_i]; if (!(quotedPost = g.posts[quote])) { continue; } - _ref4 = [quotedPost].concat(quotedPost.clones); - for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) { - quotedPost = _ref4[_k]; - quotelinks.push.apply(quotelinks, __slice.call(quotedPost.nodes.backlinks)); - } + qLconcat(quotedPost.nodes.quotelinks); + handleClones(quotedPost.clones); } } return quotelinks.filter(function(quotelink) { - var boardID, postID, _ref5; - _ref5 = Get.postDataFromLink(quotelink), boardID = _ref5.boardID, postID = _ref5.postID; + var boardID, postID, _ref3; + _ref3 = Get.postDataFromLink(quotelink), boardID = _ref3.boardID, postID = _ref3.postID; return boardID === post.board.ID && postID === post.ID; }); }, diff --git a/src/General/Get.coffee b/src/General/Get.coffee index f4114a676..5ec5d6a98 100755 --- a/src/General/Get.coffee +++ b/src/General/Get.coffee @@ -44,10 +44,14 @@ Get = # In every posts, # if it did quote this post, # get all their backlinks. - for ID, quoterPost of g.posts - if post.fullID in quoterPost.quotes - for quoterPost in [quoterPost].concat quoterPost.clones - quotelinks.push.apply quotelinks, quoterPost.nodes.quotelinks + qLconcat = (links) -> + quotelinks = quotelinks.concat links + handleClones = (clones) -> + for clone in clones + qLconcat clone.nodes.quotelinks + for ID, quoterPost of g.posts when post.fullID in quoterPost.quotes + qLconcat quoterPost.nodes.quotelinks + handleClones quoterPost.clones # Second: # If we have quote backlinks: # in all posts this post quoted @@ -56,8 +60,8 @@ Get = if Conf['Quote Backlinks'] for quote in post.quotes continue unless quotedPost = g.posts[quote] - for quotedPost in [quotedPost].concat quotedPost.clones - quotelinks.push.apply quotelinks, [quotedPost.nodes.backlinks...] + qLconcat quotedPost.nodes.quotelinks + handleClones quotedPost.clones # Third: # Filter out irrelevant quotelinks. quotelinks.filter (quotelink) ->