diff --git a/src/Posting/Captcha.v1.coffee b/src/Posting/Captcha.v1.coffee index 904b0f5d0..9a438d0a0 100644 --- a/src/Posting/Captcha.v1.coffee +++ b/src/Posting/Captcha.v1.coffee @@ -95,7 +95,7 @@ Captcha.v1 = setup: (focus, force) -> return unless @isEnabled and (force or @needed()) @create() - @nodes.input.focus() if focus + @nodes.input.focus() if focus and d.activeElement in [QR.nodes.status, d.body] afterSetup: -> return unless challenge = $.id 'recaptcha_challenge_field_holder' @@ -154,6 +154,7 @@ Captcha.v1 = challenge: @nodes.img.alt response: response timeout: @timeout + @captchas.sort (a, b) -> a.timeout - b.timeout @count() @destroy() @setup false, true @@ -196,6 +197,9 @@ Captcha.v1 = " (#{count} cached captchas)" @nodes.input.placeholder = placeholder @nodes.input.alt = count # For XTRM RICE. + clearTimeout @timer + if count + @timer = setTimeout @clear.bind(@), @captchas[0].timeout - Date.now() reload: (focus) -> # Recaptcha.should_focus = false: Hack to prevent the input from being focused diff --git a/src/Posting/Captcha.v2.coffee b/src/Posting/Captcha.v2.coffee index 9c8102978..9313f16af 100644 --- a/src/Posting/Captcha.v2.coffee +++ b/src/Posting/Captcha.v2.coffee @@ -42,7 +42,6 @@ Captcha.v2 = conn = new Connection window.parent, "#{location.protocol}//boards.4chan.org" conn.send {token} - shouldFocus: false timeouts: {} postsCount: 0 @@ -74,17 +73,16 @@ Captcha.v2 = setup: (focus, force) -> return unless @isEnabled and (@needed() or force) - @shouldFocus = true if focus and not QR.inBubble() + @nodes.counter.focus() if focus and d.activeElement in [QR.nodes.status, d.body] if @timeouts.destroy clearTimeout @timeouts.destroy delete @timeouts.destroy return @reload() if @nodes.container - if @shouldFocus and iframe = $ 'iframe', @nodes.container + if d.activeElement is @nodes.counter and (iframe = $ 'iframe', @nodes.container) iframe.focus() QR.focus() # Event handler not fired in Firefox - delete @shouldFocus return @nodes.container = $.el 'div', className: 'captcha-container' @@ -143,8 +141,7 @@ Captcha.v2 = if QR.nodes.el.getBoundingClientRect().bottom > doc.clientHeight QR.nodes.el.style.top = null QR.nodes.el.style.bottom = '0px' - iframe.focus() if @shouldFocus - @shouldFocus = false + iframe.focus() if d.activeElement is @nodes.counter # XXX Stop Recaptcha from changing focus from iframe -> body -> iframe on submit. $.global -> f = document.querySelector('#qr iframe') @@ -186,6 +183,7 @@ Captcha.v2 = @captchas.push response: token or $('textarea', @nodes.container).value timeout: Date.now() + @lifetime + @captchas.sort (a, b) -> a.timeout - b.timeout $.set 'captchas', @captchas @count() @@ -193,7 +191,7 @@ Captcha.v2 = if @needed() if focus if QR.cooldown.auto or Conf['Post on Captcha Completion'] - @shouldFocus = true + @nodes.counter.focus() else QR.nodes.status.focus() @reload() @@ -216,7 +214,7 @@ Captcha.v2 = @captchas = @captchas[i..] @count() $.set 'captchas', @captchas - @setup(d.activeElement is QR.nodes.status) + @setup true count: -> @nodes.counter.textContent = "Captchas: #{@captchas.length}" diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index a707e3499..99f3d29b6 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -222,8 +222,6 @@ QR = else el = err el.removeAttribute 'style' - if QR.captcha.isEnabled and /captcha|verification/i.test el.textContent - QR.captcha.setup true notice = new Notice 'warning', el QR.notifications.push notice unless Header.areNotificationsEnabled @@ -633,7 +631,9 @@ QR = if QR.captcha.isEnabled and !err captcha = QR.captcha.getOne() - err = 'No valid captcha.' unless captcha + unless captcha + err = 'No valid captcha.' + QR.captcha.setup true QR.cleanNotifications() if err @@ -773,11 +773,11 @@ QR = QR.cooldown.addMute seconds else QR.cooldown.addDelay post, seconds - QR.captcha.setup (d.activeElement is QR.nodes.status) else # stop auto-posting QR.cooldown.auto = false QR.status() QR.error err + QR.captcha.setup true return h1 = $ 'h1', resDoc @@ -815,7 +815,7 @@ QR = QR.close() else post.rm() - QR.captcha.setup(d.activeElement is QR.nodes.status) + QR.captcha.setup true QR.cooldown.add threadID, postID