From 48afb6d880aa1ad0316a0814b2b0905f49648c7c Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 23 Jan 2012 23:47:31 +0100 Subject: [PATCH] Do not cycle through board pages with Index Navigation or See next/previous thread keybinds. --- 4chan_x.user.js | 46 ++++++++++++++++------------------------------ changelog | 2 ++ script.coffee | 40 +++++++++++++--------------------------- 3 files changed, 31 insertions(+), 57 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index b587b6b9d..18a06fa11 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -947,13 +947,15 @@ keybinds.img(thread); break; case conf.nextThread: - nav.next(); + if (g.REPLY) return; + nav.scroll(+1); break; case conf.openThreadTab: keybinds.open(thread, true); break; case conf.previousThread: - nav.prev(); + if (g.REPLY) return; + nav.scroll(-1); break; case conf.update: updater.update(); @@ -1160,10 +1162,18 @@ return $.add(d.body, span); }, prev: function() { - return nav.scroll(-1); + if (g.REPLY) { + return window.scrollTo(0, 0); + } else { + return nav.scroll(-1); + } }, next: function() { - return nav.scroll(+1); + if (g.REPLY) { + return window.scrollTo(0, d.body.scrollHeight); + } else { + return nav.scroll(+1); + } }, threads: [], getThread: function(full) { @@ -1182,37 +1192,13 @@ return null; }, scroll: function(delta) { - var i, rect, thread, top, _ref; - if (g.REPLY) { - if (delta === -1) { - window.scrollTo(0, 0); - } else { - window.scrollTo(0, d.body.scrollHeight); - } - return; - } + var i, rect, thread, top, _ref, _ref2; _ref = nav.getThread(true), thread = _ref[0], i = _ref[1], rect = _ref[2]; top = rect.top; if (!((delta === -1 && Math.ceil(top) < 0) || (delta === +1 && top > 1))) { i += delta; } - if (i === -1) { - if (g.PAGENUM === 0) { - window.scrollTo(0, 0); - } else { - window.location = "" + (g.PAGENUM - 1) + "#0"; - } - return; - } - if (delta === +1) { - if (i === nav.threads.length || (innerHeight + pageYOffset === d.body.scrollHeight)) { - if ($('table.pages input[value="Next"]')) { - window.location = "" + (g.PAGENUM + 1) + "#0"; - return; - } - } - } - top = nav.threads[i].getBoundingClientRect().top; + top = (_ref2 = nav.threads[i]) != null ? _ref2.getBoundingClientRect().top : void 0; return window.scrollBy(0, top); } }; diff --git a/changelog b/changelog index 8fc026f91..e71d58f30 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ master +- Mayhem + Index Navigation and the See next/previous thread keybinds will not cycle through board pages anymore. 2.24.4 - ahokadesuka diff --git a/script.coffee b/script.coffee index 0099ea17f..5f8dd3ccd 100644 --- a/script.coffee +++ b/script.coffee @@ -692,11 +692,13 @@ keybinds = when conf.expandImages keybinds.img thread when conf.nextThread - nav.next() + return if g.REPLY + nav.scroll +1 when conf.openThreadTab keybinds.open thread, true when conf.previousThread - nav.prev() + return if g.REPLY + nav.scroll -1 when conf.update updater.update() when conf.watch @@ -828,10 +830,16 @@ nav = $.add d.body, span prev: -> - nav.scroll -1 + if g.REPLY + window.scrollTo 0, 0 + else + nav.scroll -1 next: -> - nav.scroll +1 + if g.REPLY + window.scrollTo 0, d.body.scrollHeight + else + nav.scroll +1 threads: [] @@ -847,13 +855,6 @@ nav = return null scroll: (delta) -> - if g.REPLY - if delta is -1 - window.scrollTo 0,0 - else - window.scrollTo 0, d.body.scrollHeight - return - [thread, i, rect] = nav.getThread true {top} = rect @@ -863,22 +864,7 @@ nav = unless (delta is -1 and Math.ceil(top) < 0) or (delta is +1 and top > 1) i += delta - if i is -1 - if g.PAGENUM is 0 - window.scrollTo 0, 0 - else - window.location = "#{g.PAGENUM - 1}#0" - return - if delta is +1 - # if we're at the last thread, or we're at the bottom of the page. - # kind of hackish, what we really need to do is make nav.getThread smarter. - if i is nav.threads.length or (innerHeight + pageYOffset == d.body.scrollHeight) - if $ 'table.pages input[value="Next"]' - window.location = "#{g.PAGENUM + 1}#0" - return - #TODO sfx - - {top} = nav.threads[i].getBoundingClientRect() + {top} = nav.threads[i]?.getBoundingClientRect() window.scrollBy 0, top options =