diff --git a/4chan_x.user.js b/4chan_x.user.js index fdd3c3564..da1764adb 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -875,12 +875,11 @@ return $.on(d, 'keydown', keybinds.keydown); }, keydown: function(e) { - var o, range, selEnd, selStart, ta, thread, valEnd, valMid, valStart, value, _ref, _ref2, _ref3; + var o, range, selEnd, selStart, ta, thread, valEnd, valMid, valStart, value, _ref, _ref2; updater.focus = true; - if (((_ref = e.target.nodeName) === 'TEXTAREA' || _ref === 'INPUT') && !e.altKey && !e.ctrlKey && !(e.keyCode === 27)) { + if (!(key = keybinds.keyCode(e)) || /TEXTAREA|INPUT/.test(e.target.nodeName) && !(e.altKey || e.ctrlKey || e.keyCode === 27)) { return; } - if (!(key = keybinds.keyCode(e))) return; thread = nav.getThread(); switch (key) { case conf.openOptions: @@ -910,6 +909,10 @@ window.location = "/" + g.BOARD + "/0#0"; break; case conf.openEmptyQR: + keybinds.qr(thread); + break; + case conf.openQR: + keybinds.qr(thread, true); break; case conf.nextReply: keybinds.hl.next(thread); @@ -926,8 +929,6 @@ case conf.expandThread: expandThread.toggle(thread); break; - case conf.openQR: - break; case conf.expandImages: keybinds.img(thread); break; @@ -950,12 +951,13 @@ threadHiding.toggle(thread); break; case conf.nextPage: - if ((_ref2 = $('input[value=Next]')) != null) _ref2.click(); + if ((_ref = $('input[value=Next]')) != null) _ref.click(); break; case conf.previousPage: - if ((_ref3 = $('input[value=Previous]')) != null) _ref3.click(); + if ((_ref2 = $('input[value=Previous]')) != null) _ref2.click(); break; case conf.submit: + if (qr.el) qr.submit(); break; case conf.unreadCountTo0: unread.replies = []; @@ -1037,15 +1039,22 @@ return key; }, img: function(thread, all) { - var root, thumb; + var thumb; if (all) { return $("#imageExpand").click(); } else { - root = $('td.replyhl', thread) || thread; - thumb = $('img[md5]', root); + thumb = $('img[md5]', $('.replyhl', thread) || thread); return imgExpand.toggle(thumb.parentNode); } }, + qr: function(thread, quote) { + if (quote) { + qr.quote.call($('.quotejs + .quotejs', $('.replyhl', thread) || thread)); + } else { + qr.open(); + } + return $('textarea', qr.el).focus(); + }, open: function(thread, tab) { var id, url; id = thread.firstChild.id; @@ -1139,7 +1148,7 @@ threads: [], getThread: function(full) { var bottom, i, rect, thread, _len, _ref; - nav.threads = $$('div.thread:not([hidden])'); + nav.threads = $$('.thread:not([hidden])'); _ref = nav.threads; for (i = 0, _len = _ref.length; i < _len; i++) { thread = _ref[i]; @@ -1209,7 +1218,8 @@ } }, close: function() { - return qr.el.hidden = true; + qr.el.hidden = true; + return d.activeElement.blur(); }, hide: function() { if ($.id('autohide').checked) { @@ -1220,6 +1230,7 @@ }, error: function(err) { $('.error', qr.el).textContent = err; + qr.open(); return alert(err); }, cleanError: function() { diff --git a/script.coffee b/script.coffee index 26a7331d2..05bc1e536 100644 --- a/script.coffee +++ b/script.coffee @@ -640,8 +640,8 @@ keybinds = keydown: (e) -> updater.focus = true - return if e.target.nodeName in ['TEXTAREA', 'INPUT'] and not e.altKey and not e.ctrlKey and not (e.keyCode is 27) - return unless key = keybinds.keyCode e + if not (key = keybinds.keyCode(e)) or /TEXTAREA|INPUT/.test(e.target.nodeName) and not (e.altKey or e.ctrlKey or e.keyCode is 27) + return thread = nav.getThread() switch key @@ -670,7 +670,9 @@ keybinds = when conf.zero window.location = "/#{g.BOARD}/0#0" when conf.openEmptyQR - ;# QR + keybinds.qr thread + when conf.openQR + keybinds.qr thread, true when conf.nextReply keybinds.hl.next thread when conf.previousReply @@ -681,8 +683,6 @@ keybinds = keybinds.open thread when conf.expandThread expandThread.toggle thread - when conf.openQR - ;# QR when conf.expandImages keybinds.img thread when conf.nextThread @@ -702,7 +702,7 @@ keybinds = when conf.previousPage $('input[value=Previous]')?.click() when conf.submit - ;# QR + qr.submit() if qr.el when conf.unreadCountTo0 unread.replies = [] unread.updateTitle() @@ -739,10 +739,16 @@ keybinds = if all $("#imageExpand").click() else - root = $('td.replyhl', thread) or thread - thumb = $ 'img[md5]', root + thumb = $ 'img[md5]', $('.replyhl', thread) or thread imgExpand.toggle thumb.parentNode + qr: (thread, quote) -> + if quote + qr.quote.call $ '.quotejs + .quotejs', $('.replyhl', thread) or thread + else + qr.open() + $('textarea', qr.el).focus() + open: (thread, tab) -> id = thread.firstChild.id url = "http://boards.4chan.org/#{g.BOARD}/res/#{id}" @@ -818,7 +824,7 @@ nav = threads: [] getThread: (full) -> - nav.threads = $$ 'div.thread:not([hidden])' + nav.threads = $$ '.thread:not([hidden])' for thread, i in nav.threads rect = thread.getBoundingClientRect() {bottom} = rect @@ -881,6 +887,7 @@ qr = qr.dialog() close: -> qr.el.hidden = true + d.activeElement.blur() hide: -> if $.id('autohide').checked $.addClass qr.el, 'autohide' @@ -889,6 +896,7 @@ qr = error: (err) -> $('.error', qr.el).textContent = err + qr.open() alert err cleanError: -> $('.error', qr.el).textContent = null