diff --git a/4chan_x.user.js b/4chan_x.user.js index 36c697908..6f62a05ed 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1240,6 +1240,26 @@ $('#recaptcha_response_field').id = ''; return qr.captcha = []; }, + add: function() { + var file, files; + $('#auto', qr.el).checked = true; + file = $.el('input', { + type: 'file', + name: 'upfile' + }); + files = $('#files', qr.el); + return $.append(files, file); + }, + auto: function() { + var captcha, responseField; + responseField = $('input[name=recaptcha_response_field]', qr.el); + if (!responseField.value && (captcha = qr.captcha.shift())) { + $('input[name=recaptcha_challenge_field]', qr.el).value = captcha.challenge; + responseField.value = captcha.response; + responseField.nextSibling.textContent = qr.captcha.length; + } + return qr.submit.call($('form', qr.el)); + }, autohide: { set: function() { var _ref; @@ -1250,6 +1270,48 @@ return (_ref = $('#autohide:checked', qr.el)) != null ? _ref.click() : void 0; } }, + cb: { + autohide: function(e) { + if (this.checked) { + return $.addClass(qr.el, 'auto'); + } else { + return $.removeClass(qr.el, 'auto'); + } + }, + quote: function(e) { + e.preventDefault(); + return qr.quote(this); + } + }, + close: function() { + $.rm(qr.el); + return qr.el = null; + }, + dialog: function(link) { + var THREAD_ID, challenge, html, spoiler, submitDisabled, submitValue; + submitValue = $('#com_submit').value; + submitDisabled = $('#com_submit').disabled ? 'disabled' : ''; + THREAD_ID = g.THREAD_ID || $.x('ancestor::div[@class="thread"]/div', link).id; + spoiler = $('.postarea label') ? '' : ''; + challenge = $('input[name=recaptcha_challenge_field]').value; + html = "
Quick Reply X
" + spoiler + "
0
attach another file
"; + qr.el = ui.dialog('qr', { + top: '0px', + left: '0px' + }, html); + qr.refresh(); + $('textarea', qr.el).value = $('textarea').value; + $.bind($('input[name=name]', qr.el), 'mousedown', function(e) { + return e.stopPropagation(); + }); + $.bind($('#autohide', qr.el), 'click', qr.cb.autohide); + $.bind($('a[name=close]', qr.el), 'click', qr.close); + $.bind($('form', qr.el), 'submit', qr.submit); + $.bind($('a[name=add]', qr.el), 'click', qr.add); + $.bind($('img', qr.el), 'click', Recaptcha.reload); + $.bind($('input[name=recaptcha_response_field]', qr.el), 'keydown', Recaptcha.listener); + return $.append(d.body, qr.el); + }, message: function(e) { var data, duration, file, oldFile; Recaptcha.reload(); @@ -1288,29 +1350,12 @@ quote = $('a.quotejs:not(:first-child)', root); return $.bind(quote, 'click', qr.cb.quote); }, - cb: { - autohide: function(e) { - if (this.checked) { - return $.addClass(qr.el, 'auto'); - } else { - return $.removeClass(qr.el, 'auto'); - } - }, - quote: function(e) { - e.preventDefault(); - return qr.quote(this); + persist: function() { + qr.dialog(); + if (conf['Auto Hide QR']) { + return qr.autohide.set(); } }, - auto: function() { - var captcha, responseField; - responseField = $('input[name=recaptcha_response_field]', qr.el); - if (!responseField.value && (captcha = qr.captcha.shift())) { - $('input[name=recaptcha_challenge_field]', qr.el).value = captcha.challenge; - responseField.value = captcha.response; - responseField.nextSibling.textContent = qr.captcha.length; - } - return qr.submit.call($('form', qr.el)); - }, push: function() { this.nextSibling.textContent = qr.captcha.push({ challenge: $('input[name=recaptcha_challenge_field]', qr.el).value, @@ -1319,6 +1364,37 @@ Recaptcha.reload(); return this.value = ''; }, + quote: function(link) { + var id, s, selection, selectionID, ta, text, _ref; + if (qr.el) { + qr.autohide.unset(); + } else { + qr.dialog(link); + } + id = link.textContent; + text = ">>" + id + "\n"; + selection = window.getSelection(); + if (s = selection.toString()) { + selectionID = (_ref = $.x('preceding::input[@type="checkbox"][1]', selection.anchorNode)) != null ? _ref.name : void 0; + if (selectionID === id) { + s = s.replace(/\n/g, '\n>'); + text += ">" + s + "\n"; + } + } + ta = $('textarea', qr.el); + ta.focus(); + return ta.value += text; + }, + refresh: function() { + var auto, c, m; + auto = $('#auto', qr.el).checked; + $('form', qr.el).reset(); + $('#auto', qr.el).checked = auto; + c = d.cookie; + $('input[name=name]', qr.el).value = (m = c.match(/4chan_name=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; + $('input[name=email]', qr.el).value = (m = c.match(/4chan_email=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; + return $('input[name=pwd]', qr.el).value = (m = c.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $('input[name=pwd]').value; + }, submit: function(e) { var id, inputfile, isQR, op; if (conf['Auto Watch Reply'] && conf['Thread Watcher']) { @@ -1354,82 +1430,6 @@ return qr.sage = /sage/i.test($('input[name=email]', this).value); } }, - quote: function(link) { - var id, s, selection, selectionID, ta, text, _ref; - if (qr.el) { - qr.autohide.unset(); - } else { - qr.dialog(link); - } - id = link.textContent; - text = ">>" + id + "\n"; - selection = window.getSelection(); - if (s = selection.toString()) { - selectionID = (_ref = $.x('preceding::input[@type="checkbox"][1]', selection.anchorNode)) != null ? _ref.name : void 0; - if (selectionID === id) { - s = s.replace(/\n/g, '\n>'); - text += ">" + s + "\n"; - } - } - ta = $('textarea', qr.el); - ta.focus(); - return ta.value += text; - }, - refresh: function() { - var auto, c, m; - auto = $('#auto', qr.el).checked; - $('form', qr.el).reset(); - $('#auto', qr.el).checked = auto; - c = d.cookie; - $('input[name=name]', qr.el).value = (m = c.match(/4chan_name=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; - $('input[name=email]', qr.el).value = (m = c.match(/4chan_email=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; - return $('input[name=pwd]', qr.el).value = (m = c.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $('input[name=pwd]').value; - }, - add: function() { - var file, files; - $('#auto', qr.el).checked = true; - file = $.el('input', { - type: 'file', - name: 'upfile' - }); - files = $('#files', qr.el); - return $.append(files, file); - }, - dialog: function(link) { - var THREAD_ID, challenge, html, spoiler, submitDisabled, submitValue; - submitValue = $('#com_submit').value; - submitDisabled = $('#com_submit').disabled ? 'disabled' : ''; - THREAD_ID = g.THREAD_ID || $.x('ancestor::div[@class="thread"]/div', link).id; - spoiler = $('.postarea label') ? '' : ''; - challenge = $('input[name=recaptcha_challenge_field]').value; - html = "
Quick Reply X
" + spoiler + "
0
attach another file
"; - qr.el = ui.dialog('qr', { - top: '0px', - left: '0px' - }, html); - qr.refresh(); - $('textarea', qr.el).value = $('textarea').value; - $.bind($('input[name=name]', qr.el), 'mousedown', function(e) { - return e.stopPropagation(); - }); - $.bind($('#autohide', qr.el), 'click', qr.cb.autohide); - $.bind($('a[name=close]', qr.el), 'click', qr.close); - $.bind($('form', qr.el), 'submit', qr.submit); - $.bind($('a[name=add]', qr.el), 'click', qr.add); - $.bind($('img', qr.el), 'click', Recaptcha.reload); - $.bind($('input[name=recaptcha_response_field]', qr.el), 'keydown', Recaptcha.listener); - return $.append(d.body, qr.el); - }, - persist: function() { - qr.dialog(); - if (conf['Auto Hide QR']) { - return qr.autohide.set(); - } - }, - close: function() { - $.rm(qr.el); - return qr.el = null; - }, sys: function() { var c, duration, id, noko, recaptcha, sage, search, thread, url, watch, _, _ref; if (recaptcha = $('#recaptcha_response_field')) { diff --git a/script.coffee b/script.coffee index a0387cc81..76b0fa0f6 100644 --- a/script.coffee +++ b/script.coffee @@ -978,44 +978,26 @@ qr = $('#recaptcha_response_field').id = '' qr.captcha = [] + add: -> + $('#auto', qr.el).checked = true + file = $.el 'input', type: 'file', name: 'upfile' + files = $ '#files', qr.el + $.append files, file + + auto: -> + responseField = $ 'input[name=recaptcha_response_field]', qr.el + if !responseField.value and captcha = qr.captcha.shift() + $('input[name=recaptcha_challenge_field]', qr.el).value = captcha.challenge + responseField.value = captcha.response + responseField.nextSibling.textContent = qr.captcha.length + qr.submit.call $ 'form', qr.el + autohide: set: -> $('#autohide:not(:checked)', qr.el)?.click() unset: -> $('#autohide:checked', qr.el)?.click() - message: (e) -> - Recaptcha.reload() - $('iframe[name=iframe]').src = 'about:blank' - - {data} = e - if data # error message - data = JSON.parse data - $.extend $('#error', qr.el), data - $('input[name=recaptcha_response_field]', qr.el).value = '' - qr.autohide.unset() - if data.textContent is 'You seem to have mistyped the verification.' - qr.auto() - return - - if qr.el - file = $ '#files input', qr.el - if g.REPLY and (conf['Persistent QR'] or file) - qr.refresh() - if file - oldFile = $ '#qr_form input[type=file]', qr.el - $.replace oldFile, file - else - qr.close() - if conf['Cooldown'] - duration = if qr.sage then 60 else 30 - $.setValue g.BOARD+'/cooldown', Date.now() + duration * 1000 - cooldown.start() - - node: (root) -> - quote = $ 'a.quotejs:not(:first-child)', root - $.bind quote, 'click', qr.cb.quote - cb: autohide: (e) -> if @checked @@ -1027,81 +1009,9 @@ qr = e.preventDefault() qr.quote @ - auto: -> - responseField = $ 'input[name=recaptcha_response_field]', qr.el - if !responseField.value and captcha = qr.captcha.shift() - $('input[name=recaptcha_challenge_field]', qr.el).value = captcha.challenge - responseField.value = captcha.response - responseField.nextSibling.textContent = qr.captcha.length - qr.submit.call $ 'form', qr.el - - push: -> - @nextSibling.textContent = qr.captcha.push - challenge: $('input[name=recaptcha_challenge_field]', qr.el).value - response: @value - Recaptcha.reload() - @value = '' - - submit: (e) -> - if conf['Auto Watch Reply'] and conf['Thread Watcher'] - if g.REPLY and $('img.favicon').src is Favicon.empty - watcher.watch null, g.THREAD_ID - else - id = $('input[name=resto]', qr.el).value - op = $.id id - if $('img.favicon', op).src is Favicon.empty - watcher.watch op, id - - isQR = @id is 'qr_form' - - inputfile = $('input[type=file]', @) - if inputfile.value and inputfile.files[0].size > $('input[name=MAX_FILE_SIZE]').value - e.preventDefault() if e - if isQR - $('#error', qr.el).textContent = 'Error: File too large.' - else - alert 'Error: File too large.' - - else if isQR - if !e then @submit() - $('#error', qr.el).textContent = '' - qr.autohide.set() if conf['Auto Hide QR'] - qr.sage = /sage/i.test $('input[name=email]', @).value - - quote: (link) -> - if qr.el - qr.autohide.unset() - else - qr.dialog link - - id = link.textContent - text = ">>#{id}\n" - - selection = window.getSelection() - if s = selection.toString() - selectionID = $.x('preceding::input[@type="checkbox"][1]', selection.anchorNode)?.name - if selectionID == id - s = s.replace /\n/g, '\n>' - text += ">#{s}\n" - - ta = $ 'textarea', qr.el - ta.focus() - ta.value += text - - refresh: -> - auto = $('#auto', qr.el).checked - $('form', qr.el).reset() - $('#auto', qr.el).checked = auto - c = d.cookie - $('input[name=name]', qr.el).value = if m = c.match(/4chan_name=([^;]+)/) then decodeURIComponent m[1] else '' - $('input[name=email]', qr.el).value = if m = c.match(/4chan_email=([^;]+)/) then decodeURIComponent m[1] else '' - $('input[name=pwd]', qr.el).value = if m = c.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('input[name=pwd]').value - - add: -> - $('#auto', qr.el).checked = true - file = $.el 'input', type: 'file', name: 'upfile' - files = $ '#files', qr.el - $.append files, file + close: -> + $.rm qr.el + qr.el = null dialog: (link) -> submitValue = $('#com_submit').value @@ -1146,13 +1056,103 @@ qr = $.append d.body, qr.el + message: (e) -> + Recaptcha.reload() + $('iframe[name=iframe]').src = 'about:blank' + + {data} = e + if data # error message + data = JSON.parse data + $.extend $('#error', qr.el), data + $('input[name=recaptcha_response_field]', qr.el).value = '' + qr.autohide.unset() + if data.textContent is 'You seem to have mistyped the verification.' + qr.auto() + return + + if qr.el + file = $ '#files input', qr.el + if g.REPLY and (conf['Persistent QR'] or file) + qr.refresh() + if file + oldFile = $ '#qr_form input[type=file]', qr.el + $.replace oldFile, file + else + qr.close() + if conf['Cooldown'] + duration = if qr.sage then 60 else 30 + $.setValue g.BOARD+'/cooldown', Date.now() + duration * 1000 + cooldown.start() + + node: (root) -> + quote = $ 'a.quotejs:not(:first-child)', root + $.bind quote, 'click', qr.cb.quote + persist: -> qr.dialog() qr.autohide.set() if conf['Auto Hide QR'] - close: -> - $.rm qr.el - qr.el = null + push: -> + @nextSibling.textContent = qr.captcha.push + challenge: $('input[name=recaptcha_challenge_field]', qr.el).value + response: @value + Recaptcha.reload() + @value = '' + + quote: (link) -> + if qr.el + qr.autohide.unset() + else + qr.dialog link + + id = link.textContent + text = ">>#{id}\n" + + selection = window.getSelection() + if s = selection.toString() + selectionID = $.x('preceding::input[@type="checkbox"][1]', selection.anchorNode)?.name + if selectionID == id + s = s.replace /\n/g, '\n>' + text += ">#{s}\n" + + ta = $ 'textarea', qr.el + ta.focus() + ta.value += text + + refresh: -> + auto = $('#auto', qr.el).checked + $('form', qr.el).reset() + $('#auto', qr.el).checked = auto + c = d.cookie + $('input[name=name]', qr.el).value = if m = c.match(/4chan_name=([^;]+)/) then decodeURIComponent m[1] else '' + $('input[name=email]', qr.el).value = if m = c.match(/4chan_email=([^;]+)/) then decodeURIComponent m[1] else '' + $('input[name=pwd]', qr.el).value = if m = c.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('input[name=pwd]').value + + submit: (e) -> + if conf['Auto Watch Reply'] and conf['Thread Watcher'] + if g.REPLY and $('img.favicon').src is Favicon.empty + watcher.watch null, g.THREAD_ID + else + id = $('input[name=resto]', qr.el).value + op = $.id id + if $('img.favicon', op).src is Favicon.empty + watcher.watch op, id + + isQR = @id is 'qr_form' + + inputfile = $('input[type=file]', @) + if inputfile.value and inputfile.files[0].size > $('input[name=MAX_FILE_SIZE]').value + e.preventDefault() if e + if isQR + $('#error', qr.el).textContent = 'Error: File too large.' + else + alert 'Error: File too large.' + + else if isQR + if !e then @submit() + $('#error', qr.el).textContent = '' + qr.autohide.set() if conf['Auto Hide QR'] + qr.sage = /sage/i.test $('input[name=email]', @).value sys: -> if recaptcha = $ '#recaptcha_response_field' #post reporting