From 898cfda2fd3c90353d54789978cfefc491d7915b Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 7 Jan 2014 10:23:48 -0700 Subject: [PATCH] That translates to leaner JS --- builds/4chan-X.user.js | 45 ++++++++++++---------------- builds/crx/script.js | 45 ++++++++++++---------------- src/Quotelinks/QuoteThreading.coffee | 10 +++++-- 3 files changed, 46 insertions(+), 54 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 981476491..e5739b798 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -5016,44 +5016,37 @@ return true; }, toggle: function() { - var ID, container, containers, post, posts, thread, _i, _j, _len, _len1, _ref, _results; + var ID, container, containers, nodes, post, posts, thread, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _results; if (QuoteThreading.enabled = this.checked) { return QuoteThreading.force(); } else { thread = $('.thread'); - posts = (function() { - var _ref, _results; - _ref = g.posts; - _results = []; - for (ID in _ref) { - post = _ref[ID]; - if (!(post === post.thread.OP || post.isClone)) { - _results.push(post); - } + posts = []; + nodes = []; + _ref = g.posts; + for (ID in _ref) { + post = _ref[ID]; + if (!(post === post.thread.OP || post.isClone)) { + posts.push(post); } - return _results; - })(); + } posts.sort(function(a, b) { return a.ID - b.ID; }); - $.add(thread, (function() { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = posts.length; _i < _len; _i++) { - post = posts[_i]; - _results.push(post.nodes.root); - } - return _results; - })()); + for (_i = 0, _len = posts.length; _i < _len; _i++) { + post = posts[_i]; + nodes.push(post.nodes.root); + } + $.add(thread, nodes); containers = $$('.threadContainer', thread); - for (_i = 0, _len = containers.length; _i < _len; _i++) { - container = containers[_i]; + for (_j = 0, _len1 = containers.length; _j < _len1; _j++) { + container = containers[_j]; $.rm(container); } - _ref = $$('.threadOP'); + _ref1 = $$('.threadOP'); _results = []; - for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { - post = _ref[_j]; + for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { + post = _ref1[_k]; _results.push($.rmClass(post, 'threadOP')); } return _results; diff --git a/builds/crx/script.js b/builds/crx/script.js index 72b8554bc..178e32aa7 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -5019,44 +5019,37 @@ return true; }, toggle: function() { - var ID, container, containers, post, posts, thread, _i, _j, _len, _len1, _ref, _results; + var ID, container, containers, nodes, post, posts, thread, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _results; if (QuoteThreading.enabled = this.checked) { return QuoteThreading.force(); } else { thread = $('.thread'); - posts = (function() { - var _ref, _results; - _ref = g.posts; - _results = []; - for (ID in _ref) { - post = _ref[ID]; - if (!(post === post.thread.OP || post.isClone)) { - _results.push(post); - } + posts = []; + nodes = []; + _ref = g.posts; + for (ID in _ref) { + post = _ref[ID]; + if (!(post === post.thread.OP || post.isClone)) { + posts.push(post); } - return _results; - })(); + } posts.sort(function(a, b) { return a.ID - b.ID; }); - $.add(thread, (function() { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = posts.length; _i < _len; _i++) { - post = posts[_i]; - _results.push(post.nodes.root); - } - return _results; - })()); + for (_i = 0, _len = posts.length; _i < _len; _i++) { + post = posts[_i]; + nodes.push(post.nodes.root); + } + $.add(thread, nodes); containers = $$('.threadContainer', thread); - for (_i = 0, _len = containers.length; _i < _len; _i++) { - container = containers[_i]; + for (_j = 0, _len1 = containers.length; _j < _len1; _j++) { + container = containers[_j]; $.rm(container); } - _ref = $$('.threadOP'); + _ref1 = $$('.threadOP'); _results = []; - for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { - post = _ref[_j]; + for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { + post = _ref1[_k]; _results.push($.rmClass(post, 'threadOP')); } return _results; diff --git a/src/Quotelinks/QuoteThreading.coffee b/src/Quotelinks/QuoteThreading.coffee index 25ab3f325..f479e6fc9 100755 --- a/src/Quotelinks/QuoteThreading.coffee +++ b/src/Quotelinks/QuoteThreading.coffee @@ -91,9 +91,15 @@ QuoteThreading = else thread = $('.thread') - posts = (post for ID, post of g.posts when not (post is post.thread.OP or post.isClone)) + posts = [] + nodes = [] + + posts.push post for ID, post of g.posts when not (post is post.thread.OP or post.isClone) posts.sort (a, b) -> a.ID - b.ID - $.add thread, (post.nodes.root for post in posts) + + nodes.push post.nodes.root for post in posts + $.add thread, nodes + containers = $$ '.threadContainer', thread $.rm container for container in containers $.rmClass post, 'threadOP' for post in $$ '.threadOP'