From 1c9a0a641291cacdc7d4f0084a611d606a861ffb Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 26 Jun 2011 01:03:43 +0200 Subject: [PATCH] Keep the same orders in keybinds switch, change the next/prev replies to reply navigation. --- 4chan_x.user.js | 139 ++++++++++++++++++++---------------------------- script.coffee | 123 +++++++++++++++++++----------------------- 2 files changed, 113 insertions(+), 149 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index c396da7ac..f0ae0a3c7 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -136,7 +136,7 @@ expandThread: 'e', watch: 'w', hide: 'x', - expandImages: 'm', + expandImage: 'm', expandAllImages: 'M', update: 'u' }, @@ -739,7 +739,7 @@ keybinds.expandThread = $.getValue('key/expandThread', config.hotkeys.expandThread); keybinds.watch = $.getValue('key/watch', config.hotkeys.watch); keybinds.hide = $.getValue('key/hide', config.hotkeys.hide); - keybinds.expandImages = $.getValue('key/expandImages', config.hotkeys.expandImages); + keybinds.expandImage = $.getValue('key/expandImage', config.hotkeys.expandImage); keybinds.expandAllImages = $.getValue('key/expandAllImages', config.hotkeys.expandAllImages); keybinds.update = $.getValue('key/update', config.hotkeys.update); return $.bind(d, 'keydown', keybinds.cb.keydown); @@ -781,51 +781,31 @@ range = valStart.length + valMid.length; ta.setSelectionRange(range, range); break; - case keybinds.zero: - window.location = "/" + g.BOARD + "/0#0"; + case keybinds.openQR: + keybinds.qr(thread, true); break; case keybinds.openEmptyQR: keybinds.qr(thread); break; + case keybinds.submit: + if (qr = $('#qr_form')) { + qr.submit(); + } else { + $('.postarea form').submit(); + } + break; case keybinds.nextReply: keybinds.hl.next(thread); break; case keybinds.previousReply: keybinds.hl.prev(thread); break; - case keybinds.expandAllImages: - keybinds.img(thread, true); - break; - case keybinds.openThread: - keybinds.open(thread); - break; - case keybinds.expandThread: - expandThread.toggle(thread); - break; - case keybinds.openQR: - keybinds.qr(thread, true); - break; - case keybinds.expandImages: - keybinds.img(thread); - break; case keybinds.nextThread: nav.next(); break; - case keybinds.openThreadTab: - keybinds.open(thread, true); - break; case keybinds.previousThread: nav.prev(); break; - case keybinds.update: - updater.update(); - break; - case keybinds.watch: - watcher.toggle(thread); - break; - case keybinds.hide: - threadHiding.toggle(thread); - break; case keybinds.nextPage: if ((_ref2 = $('input[value=Next]')) != null) { _ref2.click(); @@ -836,12 +816,32 @@ _ref3.click(); } break; - case keybinds.submit: - if (qr = $('#qr_form')) { - qr.submit(); - } else { - $('.postarea form').submit(); - } + case keybinds.zero: + window.location = "/" + g.BOARD + "/0#0"; + break; + case keybinds.openThreadTab: + keybinds.open(thread, true); + break; + case keybinds.openThread: + keybinds.open(thread); + break; + case keybinds.expandThread: + expandThread.toggle(thread); + break; + case keybinds.watch: + watcher.toggle(thread); + break; + case keybinds.hide: + threadHiding.toggle(thread); + break; + case keybinds.expandImage: + keybinds.img(thread); + break; + case keybinds.expandAllImages: + keybinds.img(thread, true); + break; + case keybinds.update: + updater.update(); break; default: return; @@ -878,8 +878,8 @@ }, qr: function(thread, quote) { var qrLink; - if (!(qrLink = $('td.replyhl span[id] a:not(:first-child)', thread))) { - qrLink = $("span[id^=nothread] a:not(:first-child)", thread); + if (!(qrLink = $('.replyhl .quotejs + a', thread))) { + qrLink = $('.op .quotejs + a', thread); } if (quote) { return qr.quote(qrLink); @@ -902,53 +902,32 @@ }, hl: { next: function(thread) { - var next, rect, replies, reply, td, top, _i, _len; + var next, td; if (td = $('td.replyhl', thread)) { - td.className = 'reply'; - rect = td.getBoundingClientRect(); - if (rect.top > 0 && rect.bottom < d.body.clientHeight) { - next = $.x('following::td[@class="reply"]', td); - rect = next.getBoundingClientRect(); - if (rect.top > 0 && rect.bottom < d.body.clientHeight) { - next.className = 'replyhl'; - } - return; - } - } - replies = $$('td.reply', thread); - for (_i = 0, _len = replies.length; _i < _len; _i++) { - reply = replies[_i]; - top = reply.getBoundingClientRect().top; - if (top > 0) { - reply.className = 'replyhl'; - return; + if (next = $.x('following::td[@class="reply"]', td)) { + td.className = 'reply'; + next.className = 'replyhl'; + return location.hash = "#" + next.id; } + } else { + td = $('td.reply', thread); + td.className = 'replyhl'; + return window.location.hash = "#" + td.id; } }, prev: function(thread) { - var bot, height, prev, rect, replies, reply, td, _i, _len; + var prev, replies, td; if (td = $('td.replyhl', thread)) { - td.className = 'reply'; - rect = td.getBoundingClientRect(); - if (rect.top > 0 && rect.bottom < d.body.clientHeight) { - prev = $.x('preceding::td[@class="reply"][1]', td); - rect = prev.getBoundingClientRect(); - if (rect.top > 0 && rect.bottom < d.body.clientHeight) { - prev.className = 'replyhl'; - } - return; - } - } - replies = $$('td.reply', thread); - replies.reverse(); - height = d.body.clientHeight; - for (_i = 0, _len = replies.length; _i < _len; _i++) { - reply = replies[_i]; - bot = reply.getBoundingClientRect().bottom; - if (bot < height) { - reply.className = 'replyhl'; - return; + if (prev = $.x('preceding::td[@class="reply"]', td)) { + td.className = 'reply'; + prev.className = 'replyhl'; + return location.hash = "#" + prev.id; } + } else { + replies = $$('td.reply', thread); + replies.reverse(); + replies[0].className = 'replyhl'; + return window.location.hash = "#" + replies[0].id; } } } @@ -1049,7 +1028,7 @@ var arr, checked, description, dialog, hiddenNum, hiddenThreads, html, input, key, li, link, main, obj, overlay, ul, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3, _ref4; hiddenThreads = $.getValue("hiddenThreads/" + g.BOARD + "/", {}); hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length; - html = "

"; + html = "

"; dialog = $.el('div', { id: 'options', innerHTML: html diff --git a/script.coffee b/script.coffee index a5b282c22..ca4f600d0 100644 --- a/script.coffee +++ b/script.coffee @@ -72,7 +72,7 @@ config = expandThread: 'e' watch: 'w' hide: 'x' - expandImages: 'm' + expandImage: 'm' expandAllImages: 'M' update: 'u' updater: @@ -532,7 +532,7 @@ keybinds = keybinds.expandThread = $.getValue 'key/expandThread', config.hotkeys.expandThread keybinds.watch = $.getValue 'key/watch', config.hotkeys.watch keybinds.hide = $.getValue 'key/hide', config.hotkeys.hide - keybinds.expandImages = $.getValue 'key/expandImages', config.hotkeys.expandImages + keybinds.expandImage = $.getValue 'key/expandImage', config.hotkeys.expandImage keybinds.expandAllImages = $.getValue 'key/expandAllImages', config.hotkeys.expandAllImages keybinds.update = $.getValue 'key/update', config.hotkeys.update @@ -567,45 +567,45 @@ keybinds = ta.value = valStart + valMid + valEnd range = valStart.length + valMid.length ta.setSelectionRange range, range - when keybinds.zero - window.location = "/#{g.BOARD}/0#0" - when keybinds.openEmptyQR - keybinds.qr thread - when keybinds.nextReply - keybinds.hl.next thread - when keybinds.previousReply - keybinds.hl.prev thread - when keybinds.expandAllImages - keybinds.img thread, true - when keybinds.openThread - keybinds.open thread - when keybinds.expandThread - expandThread.toggle thread when keybinds.openQR keybinds.qr thread, true - when keybinds.expandImages - keybinds.img thread - when keybinds.nextThread - nav.next() - when keybinds.openThreadTab - keybinds.open thread, true - when keybinds.previousThread - nav.prev() - when keybinds.update - updater.update() - when keybinds.watch - watcher.toggle thread - when keybinds.hide - threadHiding.toggle thread - when keybinds.nextPage - $('input[value=Next]')?.click() - when keybinds.previousPage - $('input[value=Previous]')?.click() + when keybinds.openEmptyQR + keybinds.qr thread when keybinds.submit if qr = $('#qr_form') qr.submit() else $('.postarea form').submit() + when keybinds.nextReply + keybinds.hl.next thread + when keybinds.previousReply + keybinds.hl.prev thread + when keybinds.nextThread + nav.next() + when keybinds.previousThread + nav.prev() + when keybinds.nextPage + $('input[value=Next]')?.click() + when keybinds.previousPage + $('input[value=Previous]')?.click() + when keybinds.zero + window.location = "/#{g.BOARD}/0#0" + when keybinds.openThreadTab + keybinds.open thread, true + when keybinds.openThread + keybinds.open thread + when keybinds.expandThread + expandThread.toggle thread + when keybinds.watch + watcher.toggle thread + when keybinds.hide + threadHiding.toggle thread + when keybinds.expandImage + keybinds.img thread + when keybinds.expandAllImages + keybinds.img thread, true + when keybinds.update + updater.update() else return e.preventDefault() @@ -633,8 +633,8 @@ keybinds = imgExpand.toggle thumb.parentNode qr: (thread, quote) -> - unless qrLink = $ 'td.replyhl span[id] a:not(:first-child)', thread - qrLink = $ "span[id^=nothread] a:not(:first-child)", thread + unless qrLink = $ '.replyhl .quotejs + a', thread + qrLink = $ '.op .quotejs + a', thread if quote qr.quote qrLink @@ -654,41 +654,26 @@ keybinds = hl: next: (thread) -> if td = $ 'td.replyhl', thread - td.className = 'reply' - rect = td.getBoundingClientRect() - if rect.top > 0 and rect.bottom < d.body.clientHeight #you're fully visible - next = $.x 'following::td[@class="reply"]', td - rect = next.getBoundingClientRect() - if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the next - next.className = 'replyhl' - return - - replies = $$ 'td.reply', thread - for reply in replies - top = reply.getBoundingClientRect().top - if top > 0 - reply.className = 'replyhl' - return + if next = $.x 'following::td[@class="reply"]', td + td.className = 'reply' + next.className = 'replyhl' + location.hash = "##{next.id}" + else + td = $ 'td.reply', thread + td.className = 'replyhl' + window.location.hash = "##{td.id}" prev: (thread) -> if td = $ 'td.replyhl', thread - td.className = 'reply' - rect = td.getBoundingClientRect() - if rect.top > 0 and rect.bottom < d.body.clientHeight #you're fully visible - prev = $.x 'preceding::td[@class="reply"][1]', td - rect = prev.getBoundingClientRect() - if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the prev - prev.className = 'replyhl' - return - - replies = $$ 'td.reply', thread - replies.reverse() - height = d.body.clientHeight - for reply in replies - bot = reply.getBoundingClientRect().bottom - if bot < height - reply.className = 'replyhl' - return + if prev = $.x 'preceding::td[@class="reply"]', td + td.className = 'reply' + prev.className = 'replyhl' + location.hash = "##{prev.id}" + else + replies = $$ 'td.reply', thread + replies.reverse() + replies[0].className = 'replyhl' + window.location.hash = "##{replies[0].id}" nav = # ◀ ▶ @@ -836,7 +821,7 @@ options = Expand thread Watch thread Hide thread - Expand selected image + Expand selected image Expand all images Update now