diff --git a/4chan_x.coffee b/4chan_x.coffee index fbb68518a..a978ed718 100644 --- a/4chan_x.coffee +++ b/4chan_x.coffee @@ -30,7 +30,7 @@ config = AEOS = init: -> #x-browser - unless GM_deleteValue? + if typeof GM_deleteValue is 'undefined' window.GM_setValue = (name, value) -> value = (typeof value)[0] + value localStorage.setItem name, value @@ -38,14 +38,14 @@ AEOS = unless value = localStorage.getItem name return defaultValue type = value[0] - value = value.substring 1 + value = value[1..] switch type when 'b' - return value == 'true' + value == 'true' when 'n' - return Number value + Number value else - return value + value window.GM_addStyle = (css) -> style = document.createElement 'style' style.type = 'text/css' @@ -405,7 +405,10 @@ keypress = (e) -> when "I" unless qrLink = $ 'td.replyhl span[id] a:not(:first-child)' qrLink = $ "span[id^=nothread] a:not(:first-child)" - quickReply.call qrLink + if e.shiftKey + quickReply qrLink + else + quickReply qrLink, qrText qrLink when "J" if e.shiftKey if td = $ 'td.replyhl' @@ -457,7 +460,10 @@ keypress = (e) -> [thread] = getThread() unless qrLink = $ 'td.replyhl span[id] a:not(:first-child)', thread qrLink = $ "span#nothread#{thread.id} a:not(:first-child)", thread - quickReply.call qrLink + if e.shiftKey + quickReply qrLink + else + quickReply qrLink, qrText qrLink when "J" if e.shiftKey [thread] = getThread() @@ -568,7 +574,23 @@ parseResponse = (responseText) -> opbq = $ 'blockquote', body return [replies, opbq] -quickReply = (e) -> +qrListener = (e) -> + e.preventDefault() + link = e.target + text = qrText link + quickReply link, text + +qrText = (link) -> + #we can't just use textContent b/c of the xxxs. goddamit moot. + text = '>>' + link.parentNode.id.match(/\d+$/)[0] + '\n' + + selection = window.getSelection() + id = x('preceding::span[@id][1]', selection.anchorNode)?.id + text += selection.toString() if id is link.id + + text + +quickReply = (link, text) -> unless qr = $ '#qr' #make quick reply dialog qr = AEOS.makeDialog 'qr', 'topleft' @@ -598,15 +620,13 @@ quickReply = (e) -> m clone, listener: ['submit', formSubmit] target: 'iframe' - if getConfig 'Keybinds' - inputs = $$ 'input[type=text], textarea', clone if not g.REPLY #figure out which thread we're replying to xpath = 'preceding::span[@class="postername"][1]/preceding::input[1]' input = n 'input', type: 'hidden' name: 'resto' - value: x(xpath, this).name + value: x(xpath, link).name addTo clone, input else if getConfig 'Persistent QR' submit = $ 'input[type=submit]', clone @@ -618,18 +638,11 @@ quickReply = (e) -> inBefore submit, auto addTo qr, clone addTo d.body, qr - unless g.startup - e?.preventDefault() - $('input[title=autohide]:checked', qr)?.click() - selection = window.getSelection() - id = x('preceding::span[@id][1]', selection.anchorNode)?.id - text = selection.toString() - textarea = $('textarea', qr) - textarea.focus() - #we can't just use @textContent b/c of the xxxs. goddamit moot. - textarea.value += '>>' + @parentNode.id.match(/\d+$/)[0] + '\n' - if text and id is @parentNode.id - textarea.value += ">#{text}\n" + + $('input[title=autohide]:checked', qr)?.click() + textarea = $('textarea', qr) + textarea.focus() + if text then textarea.value += text recaptchaListener = (e) -> if e.keyCode is 8 and @value is '' @@ -983,7 +996,7 @@ if getConfig 'Quick Reply' g.callbacks.push (root) -> quotes = $$('a.quotejs:not(:first-child)', root) for quote in quotes - quote.addEventListener('click', quickReply, true) + quote.addEventListener('click', qrListener, true) #hack - nuke id so it doesn't grab focus when reloading recaptcha.id = '' diff --git a/4chan_x.js b/4chan_x.js index d788965c6..953c57774 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1,5 +1,5 @@ (function() { - var $, $$, AEOS, DAY, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expandComment, expandThread, formSubmit, g, getConfig, getThread, getTime, hide, hideReply, hideThread, href, html, i, id, iframe, iframeLoad, img, inAfter, inBefore, input, inputs, keydown, keypress, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, scroll, show, showReply, showThread, slice, span, src, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, tzOffset, up, watch, watchX, watcher, watcherUpdate, x, zeroPad, _, _base, _fn, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4; + var $, $$, AEOS, DAY, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expandComment, expandThread, formSubmit, g, getConfig, getThread, getTime, hide, hideReply, hideThread, href, html, i, id, iframe, iframeLoad, img, inAfter, inBefore, input, inputs, keydown, keypress, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, qrListener, qrText, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, scroll, show, showReply, showThread, slice, span, src, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, tzOffset, up, watch, watchX, watcher, watcherUpdate, x, zeroPad, _, _base, _fn, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4; var __slice = Array.prototype.slice, __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (this[i] === item) return i; @@ -28,7 +28,7 @@ }; AEOS = { init: function() { - if (typeof GM_deleteValue == "undefined" || GM_deleteValue === null) { + if (typeof GM_deleteValue === 'undefined') { window.GM_setValue = function(name, value) { value = (typeof value)[0] + value; return localStorage.setItem(name, value); @@ -39,7 +39,7 @@ return defaultValue; } type = value[0]; - value = value.substring(1); + value = value.slice(1); switch (type) { case 'b': return value === 'true'; @@ -520,7 +520,11 @@ if (!(qrLink = $('td.replyhl span[id] a:not(:first-child)'))) { qrLink = $("span[id^=nothread] a:not(:first-child)"); } - return quickReply.call(qrLink); + if (e.shiftKey) { + return quickReply(qrLink); + } else { + return quickReply(qrLink, qrText(qrLink)); + } break; case "J": if (e.shiftKey) { @@ -592,7 +596,11 @@ if (!(qrLink = $('td.replyhl span[id] a:not(:first-child)', thread))) { qrLink = $("span#nothread" + thread.id + " a:not(:first-child)", thread); } - return quickReply.call(qrLink); + if (e.shiftKey) { + return quickReply(qrLink); + } else { + return quickReply(qrLink, qrText(qrLink)); + } break; case "J": if (e.shiftKey) { @@ -753,8 +761,25 @@ opbq = $('blockquote', body); return [replies, opbq]; }; - quickReply = function(e) { - var auto, autoBox, autohideB, clone, closeB, form, id, input, inputs, qr, script, selection, submit, text, textarea, titlebar, xpath, _i, _len, _ref, _ref2, _ref3; + qrListener = function(e) { + var link, text; + e.preventDefault(); + link = e.target; + text = qrText(link); + return quickReply(link, text); + }; + qrText = function(link) { + var id, selection, text, _ref; + text = '>>' + link.parentNode.id.match(/\d+$/)[0] + '\n'; + selection = window.getSelection(); + id = (_ref = x('preceding::span[@id][1]', selection.anchorNode)) != null ? _ref.id : void 0; + if (id === link.id) { + text += selection.toString(); + } + return text; + }; + quickReply = function(link, text) { + var auto, autoBox, autohideB, clone, closeB, form, input, qr, script, submit, textarea, titlebar, xpath, _i, _len, _ref, _ref2; if (!(qr = $('#qr'))) { qr = AEOS.makeDialog('qr', 'topleft'); titlebar = n('div', { @@ -790,15 +815,12 @@ listener: ['submit', formSubmit], target: 'iframe' }); - if (getConfig('Keybinds')) { - inputs = $$('input[type=text], textarea', clone); - } if (!g.REPLY) { xpath = 'preceding::span[@class="postername"][1]/preceding::input[1]'; input = n('input', { type: 'hidden', name: 'resto', - value: x(xpath, this).name + value: x(xpath, link).name }); addTo(clone, input); } else if (getConfig('Persistent QR')) { @@ -815,22 +837,13 @@ addTo(qr, clone); addTo(d.body, qr); } - if (!g.startup) { - if (e != null) { - e.preventDefault(); - } - if ((_ref2 = $('input[title=autohide]:checked', qr)) != null) { - _ref2.click(); - } - selection = window.getSelection(); - id = (_ref3 = x('preceding::span[@id][1]', selection.anchorNode)) != null ? _ref3.id : void 0; - text = selection.toString(); - textarea = $('textarea', qr); - textarea.focus(); - textarea.value += '>>' + this.parentNode.id.match(/\d+$/)[0] + '\n'; - if (text && id === this.parentNode.id) { - return textarea.value += ">" + text + "\n"; - } + if ((_ref2 = $('input[title=autohide]:checked', qr)) != null) { + _ref2.click(); + } + textarea = $('textarea', qr); + textarea.focus(); + if (text) { + return textarea.value += text; } }; recaptchaListener = function(e) { @@ -1276,7 +1289,7 @@ _results = []; for (_i = 0, _len = quotes.length; _i < _len; _i++) { quote = quotes[_i]; - _results.push(quote.addEventListener('click', quickReply, true)); + _results.push(quote.addEventListener('click', qrListener, true)); } return _results; });