From 176e05bd071e4a5dc24349473be2fa466165a815 Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 17 Nov 2010 08:41:41 -0800 Subject: [PATCH] reply keybinds --- 4chan_x.coffee | 83 +++++++++++++++++--------------- 4chan_x.js | 127 +++++++++++++++++++++++++++---------------------- 2 files changed, 114 insertions(+), 96 deletions(-) diff --git a/4chan_x.coffee b/4chan_x.coffee index 5286128e0..9d0c3454e 100644 --- a/4chan_x.coffee +++ b/4chan_x.coffee @@ -387,39 +387,46 @@ keypress = (e) -> location.pathname = "/#{g.BOARD}/#{temp}#1" else if e.shiftKey - location.hash = 10 + window.scrollTo 0, 99999 else window.scrollTo 0, 0 location.hash = '' count or= 1 - switch char - when "H" - temp = g.PAGENUM - count - if temp < 0 then temp = 0 - location.pathname = "/#{g.BOARD}/#{temp}#1" - when "I" - qrLink = $ "#{hash} ~ span[id] a:not(:first-child)" - quickReply.call qrLink - ta = $ '#qr textarea' - ta.focus() - when "J" - temp = position + count - if temp > 9 then temp = 9 - location.hash = 'p' + temp - when "K" - temp = position - count - if temp < 0 then temp = 'navtop' else temp = 'p' + temp - location.hash = temp - when "L" - temp = g.PAGENUM + count - if temp > 15 then temp = 15 - location.pathname = "/#{g.BOARD}/#{temp}#0" - when "M" - img = $("#{hash} ~ img") - watch.call img - when "O" - href = $("#{hash} ~ span[id] a:last-of-type").href - GM_openInTab href + if g.REPLY + switch char + when "J" + window.scrollBy 0, 20 * count + when "K" + window.scrollBy 0, -20 * count + else + switch char + when "H" + temp = g.PAGENUM - count + if temp < 0 then temp = 0 + location.pathname = "/#{g.BOARD}/#{temp}#1" + when "I" + qrLink = $ "#{hash} ~ span[id] a:not(:first-child)" + quickReply.call qrLink + ta = $ '#qr textarea' + ta.focus() + when "J" + temp = position + count + if temp > 9 then temp = 9 + location.hash = 'p' + temp + when "K" + temp = position - count + if temp < 0 then temp = 'navtop' else temp = 'p' + temp + location.hash = temp + when "L" + temp = g.PAGENUM + count + if temp > 15 then temp = 15 + location.pathname = "/#{g.BOARD}/#{temp}#0" + when "M" + img = $("#{hash} ~ img") + watch.call img + when "O" + href = $("#{hash} ~ span[id] a:last-of-type").href + GM_openInTab href g.count = 0 keydown = (e) -> @@ -434,7 +441,7 @@ keydown = (e) -> g.keyCode = kc keyActAdd = -> - if not g.REPLY and getConfig 'Keyboard Actions' + if getConfig 'Keyboard Actions' d.addEventListener 'keydown', keydown, true d.addEventListener 'keypress', keypress, true @@ -955,6 +962,14 @@ if getConfig 'Reply Navigation' addTo span, tn(' '), up, tn(' '), down inAfter el, span +if getConfig 'Keyboard Actions' + form = $ 'div.postarea > form' + inputs = $$ 'input[type=text], textarea', form + for input in inputs + input.addEventListener 'focus', keyActRem, true + input.addEventListener 'blur', keyActAdd, true + keyActAdd() + if g.REPLY if getConfig('Quick Reply') and getConfig 'Persistent QR' quickReply() @@ -966,14 +981,6 @@ if g.REPLY d.title = "/#{g.BOARD}/ - #{text}" else #not reply - if getConfig 'Keyboard Actions' - form = $ 'div.postarea > form' - inputs = $$ 'input[type=text], textarea', form - for input in inputs - input.addEventListener 'focus', keyActRem, true - input.addEventListener 'blur', keyActAdd, true - keyActAdd() - if getConfig 'Thread Hiding' delform = $('form[name=delform]') #don't confuse other scripts diff --git a/4chan_x.js b/4chan_x.js index 261e6a7fe..c9f1f3e72 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -477,7 +477,7 @@ location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1"); } else { if (e.shiftKey) { - location.hash = 10; + window.scrollTo(0, 99999); } else { window.scrollTo(0, 0); location.hash = ''; @@ -485,51 +485,62 @@ } } count || (count = 1); - switch (char) { - case "H": - temp = g.PAGENUM - count; - if (temp < 0) { - temp = 0; - } - location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1"); - break; - case "I": - qrLink = $("" + (hash) + " ~ span[id] a:not(:first-child)"); - quickReply.call(qrLink); - ta = $('#qr textarea'); - ta.focus(); - break; - case "J": - temp = position + count; - if (temp > 9) { - temp = 9; - } - location.hash = 'p' + temp; - break; - case "K": - temp = position - count; - if (temp < 0) { - temp = 'navtop'; - } else { - temp = 'p' + temp; - } - location.hash = temp; - break; - case "L": - temp = g.PAGENUM + count; - if (temp > 15) { - temp = 15; - } - location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#0"); - break; - case "M": - img = $("" + (hash) + " ~ img"); - watch.call(img); - break; - case "O": - href = $("" + (hash) + " ~ span[id] a:last-of-type").href; - GM_openInTab(href); - break; + if (g.REPLY) { + switch (char) { + case "J": + window.scrollBy(0, 20 * count); + break; + case "K": + window.scrollBy(0, -20 * count); + break; + } + } else { + switch (char) { + case "H": + temp = g.PAGENUM - count; + if (temp < 0) { + temp = 0; + } + location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1"); + break; + case "I": + qrLink = $("" + (hash) + " ~ span[id] a:not(:first-child)"); + quickReply.call(qrLink); + ta = $('#qr textarea'); + ta.focus(); + break; + case "J": + temp = position + count; + if (temp > 9) { + temp = 9; + } + location.hash = 'p' + temp; + break; + case "K": + temp = position - count; + if (temp < 0) { + temp = 'navtop'; + } else { + temp = 'p' + temp; + } + location.hash = temp; + break; + case "L": + temp = g.PAGENUM + count; + if (temp > 15) { + temp = 15; + } + location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#0"); + break; + case "M": + img = $("" + (hash) + " ~ img"); + watch.call(img); + break; + case "O": + href = $("" + (hash) + " ~ span[id] a:last-of-type").href; + GM_openInTab(href); + break; + } } return (g.count = 0); }; @@ -545,7 +556,7 @@ } }; keyActAdd = function() { - if (!g.REPLY && getConfig('Keyboard Actions')) { + if (getConfig('Keyboard Actions')) { d.addEventListener('keydown', keydown, true); return d.addEventListener('keypress', keypress, true); } @@ -1233,6 +1244,17 @@ return _result; }); } + if (getConfig('Keyboard Actions')) { + form = $('div.postarea > form'); + inputs = $$('input[type=text], textarea', form); + _ref = inputs; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + input = _ref[_i]; + input.addEventListener('focus', keyActRem, true); + input.addEventListener('blur', keyActAdd, true); + } + keyActAdd(); + } if (g.REPLY) { if (getConfig('Quick Reply') && getConfig('Persistent QR')) { quickReply(); @@ -1247,17 +1269,6 @@ } } } else { - if (getConfig('Keyboard Actions')) { - form = $('div.postarea > form'); - inputs = $$('input[type=text], textarea', form); - _ref = inputs; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - input = _ref[_i]; - input.addEventListener('focus', keyActRem, true); - input.addEventListener('blur', keyActAdd, true); - } - keyActAdd(); - } if (getConfig('Thread Hiding')) { delform = $('form[name=delform]'); d.addEventListener('DOMNodeInserted', stopPropagation, true);