Revert "Captcha caching doesn't work on v1; remove it."
This reverts commit dcc76472932971727d8cd1bf60bf7ba6fd06460d.
This commit is contained in:
parent
69265f8f16
commit
8072a44599
@ -33,6 +33,10 @@ Captcha.v1 =
|
|||||||
$.after QR.nodes.com.parentNode, [imgContainer, input]
|
$.after QR.nodes.com.parentNode, [imgContainer, input]
|
||||||
|
|
||||||
@captchas = []
|
@captchas = []
|
||||||
|
$.get 'captchas', [], ({captchas}) ->
|
||||||
|
QR.captcha.sync captchas
|
||||||
|
QR.captcha.clear()
|
||||||
|
$.sync 'captchas', @sync
|
||||||
|
|
||||||
new MutationObserver(@afterSetup).observe $.id('captchaContainer'), childList: true
|
new MutationObserver(@afterSetup).observe $.id('captchaContainer'), childList: true
|
||||||
|
|
||||||
@ -47,6 +51,7 @@ Captcha.v1 =
|
|||||||
img.parentNode.hidden = true
|
img.parentNode.hidden = true
|
||||||
input.value = ''
|
input.value = ''
|
||||||
input.placeholder = 'Focus to load reCAPTCHA'
|
input.placeholder = 'Focus to load reCAPTCHA'
|
||||||
|
@count()
|
||||||
$.on input, 'focus click', @cb.focus
|
$.on input, 'focus click', @cb.focus
|
||||||
|
|
||||||
needed: ->
|
needed: ->
|
||||||
@ -90,6 +95,7 @@ Captcha.v1 =
|
|||||||
{img, input} = QR.captcha.nodes
|
{img, input} = QR.captcha.nodes
|
||||||
img.parentNode.hidden = false
|
img.parentNode.hidden = false
|
||||||
input.placeholder = 'Verification'
|
input.placeholder = 'Verification'
|
||||||
|
QR.captcha.count()
|
||||||
$.off input, 'focus click', QR.captcha.cb.focus
|
$.off input, 'focus click', QR.captcha.cb.focus
|
||||||
|
|
||||||
QR.captcha.nodes.challenge = challenge
|
QR.captcha.nodes.challenge = challenge
|
||||||
@ -108,13 +114,45 @@ Captcha.v1 =
|
|||||||
$.globalEval 'Recaptcha.destroy()'
|
$.globalEval 'Recaptcha.destroy()'
|
||||||
@beforeSetup()
|
@beforeSetup()
|
||||||
|
|
||||||
|
sync: (captchas=[]) ->
|
||||||
|
QR.captcha.captchas = captchas
|
||||||
|
QR.captcha.count()
|
||||||
|
|
||||||
getOne: ->
|
getOne: ->
|
||||||
|
@clear()
|
||||||
|
if captcha = @captchas.shift()
|
||||||
|
{challenge, response} = captcha
|
||||||
|
@count()
|
||||||
|
$.set 'captchas', @captchas
|
||||||
|
else
|
||||||
challenge = @nodes.img.alt
|
challenge = @nodes.img.alt
|
||||||
if /\S/.test(response = @nodes.input.value)
|
if /\S/.test(response = @nodes.input.value)
|
||||||
@destroy()
|
@destroy()
|
||||||
{challenge, response}
|
|
||||||
else
|
else
|
||||||
null
|
return null
|
||||||
|
{challenge, response}
|
||||||
|
|
||||||
|
save: ->
|
||||||
|
return unless /\S/.test(response = @nodes.input.value)
|
||||||
|
@nodes.input.value = ''
|
||||||
|
@captchas.push
|
||||||
|
challenge: @nodes.img.alt
|
||||||
|
response: response
|
||||||
|
timeout: @timeout
|
||||||
|
@count()
|
||||||
|
@reload()
|
||||||
|
$.set 'captchas', @captchas
|
||||||
|
|
||||||
|
clear: ->
|
||||||
|
return unless @captchas.length
|
||||||
|
$.forceSync 'captchas'
|
||||||
|
now = Date.now()
|
||||||
|
for captcha, i in @captchas
|
||||||
|
break if captcha.timeout > now
|
||||||
|
return unless i
|
||||||
|
@captchas = @captchas[i..]
|
||||||
|
@count()
|
||||||
|
$.set 'captchas', @captchas
|
||||||
|
|
||||||
load: ->
|
load: ->
|
||||||
return unless @nodes.challenge.firstChild
|
return unless @nodes.challenge.firstChild
|
||||||
@ -125,6 +163,20 @@ Captcha.v1 =
|
|||||||
@nodes.img.alt = challenge
|
@nodes.img.alt = challenge
|
||||||
@nodes.img.src = challenge_image.src
|
@nodes.img.src = challenge_image.src
|
||||||
@nodes.input.value = null
|
@nodes.input.value = null
|
||||||
|
@clear()
|
||||||
|
|
||||||
|
count: ->
|
||||||
|
count = if @captchas then @captchas.length else 0
|
||||||
|
placeholder = @nodes.input.placeholder.replace /\ \(.*\)$/, ''
|
||||||
|
placeholder += switch count
|
||||||
|
when 0
|
||||||
|
if placeholder is 'Verification' then ' (Shift + Enter to cache)' else ''
|
||||||
|
when 1
|
||||||
|
' (1 cached captcha)'
|
||||||
|
else
|
||||||
|
" (#{count} cached captchas)"
|
||||||
|
@nodes.input.placeholder = placeholder
|
||||||
|
@nodes.input.alt = count # For XTRM RICE.
|
||||||
|
|
||||||
reload: (focus) ->
|
reload: (focus) ->
|
||||||
# Hack to prevent the input from being focused
|
# Hack to prevent the input from being focused
|
||||||
@ -135,6 +187,8 @@ Captcha.v1 =
|
|||||||
keydown: (e) ->
|
keydown: (e) ->
|
||||||
if e.keyCode is 8 and not @nodes.input.value
|
if e.keyCode is 8 and not @nodes.input.value
|
||||||
@reload()
|
@reload()
|
||||||
|
else if e.keyCode is 13 and e.shiftKey
|
||||||
|
@save()
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user