From 69f1cc43d55949391a0c140b1259830163b5bfb2 Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 19 Nov 2010 00:05:52 -0800 Subject: [PATCH] use `getThread` in `scroll` --- 4chan_x.coffee | 15 +++++---------- 4chan_x.js | 25 ++++++++++--------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/4chan_x.coffee b/4chan_x.coffee index a8cced75c..1003e339e 100644 --- a/4chan_x.coffee +++ b/4chan_x.coffee @@ -278,7 +278,7 @@ getThread = -> for thread in threads bottom = thread.getBoundingClientRect().bottom if bottom > 0 #we have not scrolled past - return thread + return [thread, _i] formSubmit = (e) -> if span = @nextSibling @@ -420,7 +420,7 @@ keypress = (e) -> quickReply.call qrLink when "J" if e.shiftKey - thread = getThread() + [thread] = getThread() replies = $$ 'td[id]', thread for reply in replies if reply.className is 'replyhl' @@ -432,7 +432,7 @@ keypress = (e) -> scroll count when "K" if e.shiftKey - thread = getThread() + [thread] = getThread() replies = $$ 'td[id]', thread for reply in replies if reply.className is 'replyhl' @@ -637,13 +637,8 @@ report = -> input.click() scroll = (count) -> - threads = $$ 'div.thread' - for thread in threads - bottom = thread.getBoundingClientRect().bottom - if bottom > 0 #we have not scrolled past - top = thread.getBoundingClientRect().top - idx = _i - break + [thread, idx] = getThread() + top = thread.getBoundingClientRect().top if idx is 0 and top > 1 #we haven't scrolled to the first thread idx = -1 diff --git a/4chan_x.js b/4chan_x.js index 994b1bfea..367ccbde7 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -349,7 +349,7 @@ thread = _ref[_i]; bottom = thread.getBoundingClientRect().bottom; if (bottom > 0) { - return thread; + return [thread, _i]; } } return _result; @@ -523,7 +523,8 @@ return quickReply.call(qrLink); case "J": if (e.shiftKey) { - thread = getThread(); + _ref = getThread(); + thread = _ref[0]; replies = $$('td[id]', thread); _ref = replies; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -541,7 +542,8 @@ break; case "K": if (e.shiftKey) { - thread = getThread(); + _ref = getThread(); + thread = _ref[0]; replies = $$('td[id]', thread); _ref = replies; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -822,18 +824,11 @@ return input.click(); }; scroll = function(count) { - var _i, _len, _ref, bottom, hash, idx, temp, thread, threads, top; - threads = $$('div.thread'); - _ref = threads; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - thread = _ref[_i]; - bottom = thread.getBoundingClientRect().bottom; - if (bottom > 0) { - top = thread.getBoundingClientRect().top; - idx = _i; - break; - } - } + var _ref, hash, idx, temp, thread, top; + _ref = getThread(); + thread = _ref[0]; + idx = _ref[1]; + top = thread.getBoundingClientRect().top; if (idx === 0 && top > 1) { idx = -1; }