Partly restore Mayhem's captcha fix
Destroy captcha after posting instead of reloading it. Not strictly necessary since Google no longer blocks caching but a good idea to reduce the number of captcha loads. Keep captcha caching.
This commit is contained in:
parent
7a8b39f327
commit
6439b8d7aa
@ -1,8 +1,7 @@
|
|||||||
QR.captcha =
|
QR.captcha =
|
||||||
init: ->
|
init: ->
|
||||||
return if d.cookie.indexOf('pass_enabled=1') >= 0
|
return if d.cookie.indexOf('pass_enabled=1') >= 0
|
||||||
container = $.id 'captchaContainer'
|
return unless @isEnabled = !!$.id 'captchaContainer'
|
||||||
return unless @isEnabled = !!container
|
|
||||||
|
|
||||||
$.globalEval 'loadRecaptcha()' if Conf['Auto-load captcha']
|
$.globalEval 'loadRecaptcha()' if Conf['Auto-load captcha']
|
||||||
|
|
||||||
@ -10,11 +9,9 @@ QR.captcha =
|
|||||||
className: 'captcha-img'
|
className: 'captcha-img'
|
||||||
title: 'Reload reCAPTCHA'
|
title: 'Reload reCAPTCHA'
|
||||||
innerHTML: '<img>'
|
innerHTML: '<img>'
|
||||||
hidden: true
|
|
||||||
input = $.el 'input',
|
input = $.el 'input',
|
||||||
className: 'captcha-input field'
|
className: 'captcha-input field'
|
||||||
title: 'Verification'
|
title: 'Verification'
|
||||||
placeholder: 'Focus to load reCAPTCHA'
|
|
||||||
autocomplete: 'off'
|
autocomplete: 'off'
|
||||||
spellcheck: false
|
spellcheck: false
|
||||||
tabIndex: 45
|
tabIndex: 45
|
||||||
@ -22,17 +19,22 @@ QR.captcha =
|
|||||||
img: imgContainer.firstChild
|
img: imgContainer.firstChild
|
||||||
input: input
|
input: input
|
||||||
|
|
||||||
$.on input, 'focus', @setup
|
|
||||||
|
|
||||||
$.on input, 'blur', QR.focusout
|
$.on input, 'blur', QR.focusout
|
||||||
$.on input, 'focus', QR.focusin
|
$.on input, 'focus', QR.focusin
|
||||||
|
|
||||||
$.addClass QR.nodes.el, 'has-captcha'
|
$.addClass QR.nodes.el, 'has-captcha'
|
||||||
$.after QR.nodes.com.parentNode, [imgContainer, input]
|
$.after QR.nodes.com.parentNode, [imgContainer, input]
|
||||||
|
|
||||||
@setupObserver = new MutationObserver @afterSetup
|
@beforeSetup()
|
||||||
@setupObserver.observe container, childList: true
|
|
||||||
@afterSetup() # reCAPTCHA might have loaded before the QR.
|
@afterSetup() # reCAPTCHA might have loaded before the QR.
|
||||||
|
beforeSetup: ->
|
||||||
|
{img, input} = @nodes
|
||||||
|
img.parentNode.hidden = true
|
||||||
|
input.value = ''
|
||||||
|
input.placeholder = 'Focus to load reCAPTCHA'
|
||||||
|
$.on input, 'focus', @setup
|
||||||
|
@setupObserver = new MutationObserver @afterSetup
|
||||||
|
@setupObserver.observe $.id('captchaContainer'), childList: true
|
||||||
setup: ->
|
setup: ->
|
||||||
$.globalEval 'loadRecaptcha()'
|
$.globalEval 'loadRecaptcha()'
|
||||||
afterSetup: ->
|
afterSetup: ->
|
||||||
@ -47,6 +49,7 @@ QR.captcha =
|
|||||||
|
|
||||||
{img, input} = QR.captcha.nodes
|
{img, input} = QR.captcha.nodes
|
||||||
img.parentNode.hidden = false
|
img.parentNode.hidden = false
|
||||||
|
input.placeholder = 'Verification'
|
||||||
$.off input, 'focus', QR.captcha.setup
|
$.off input, 'focus', QR.captcha.setup
|
||||||
$.on input, 'keydown', QR.captcha.keydown.bind QR.captcha
|
$.on input, 'keydown', QR.captcha.keydown.bind QR.captcha
|
||||||
$.on img.parentNode, 'click', QR.captcha.reload.bind QR.captcha
|
$.on img.parentNode, 'click', QR.captcha.reload.bind QR.captcha
|
||||||
@ -61,6 +64,9 @@ QR.captcha =
|
|||||||
subtree: true
|
subtree: true
|
||||||
attributes: true
|
attributes: true
|
||||||
QR.captcha.load()
|
QR.captcha.load()
|
||||||
|
destroy: ->
|
||||||
|
$.globalEval 'Recaptcha.destroy()'
|
||||||
|
@beforeSetup()
|
||||||
|
|
||||||
sync: (captchas) ->
|
sync: (captchas) ->
|
||||||
QR.captcha.captchas = captchas
|
QR.captcha.captchas = captchas
|
||||||
@ -74,7 +80,7 @@ QR.captcha =
|
|||||||
$.set 'captchas', @captchas
|
$.set 'captchas', @captchas
|
||||||
else
|
else
|
||||||
challenge = @nodes.img.alt
|
challenge = @nodes.img.alt
|
||||||
if response = @nodes.input.value then @reload()
|
if response = @nodes.input.value then @destroy()
|
||||||
if response
|
if response
|
||||||
response = response.trim()
|
response = response.trim()
|
||||||
# one-word-captcha:
|
# one-word-captcha:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user