Fix captcha
This commit is contained in:
parent
2d830511fd
commit
26954b6755
@ -1,3 +1,4 @@
|
|||||||
|
- Fixed captcha loading in the QR.
|
||||||
- New setting: `Quote Markers`, enabled by default
|
- New setting: `Quote Markers`, enabled by default
|
||||||
- This merges `Mark Quotes of You`, `Mark OP Quotes` and `Mark Cross-thread Quotes` into one feature.
|
- This merges `Mark Quotes of You`, `Mark OP Quotes` and `Mark Cross-thread Quotes` into one feature.
|
||||||
- Backlinks now also get these markers.
|
- Backlinks now also get these markers.
|
||||||
|
|||||||
@ -1,38 +1,25 @@
|
|||||||
QR.captcha =
|
QR.captcha =
|
||||||
init: ->
|
init: ->
|
||||||
return if d.cookie.indexOf('pass_enabled=1') >= 0
|
return if d.cookie.indexOf('pass_enabled=1') >= 0
|
||||||
return unless @isEnabled = !!$.id 'captchaFormPart'
|
container = $.id 'captchaContainer'
|
||||||
$.asap (-> $.id 'recaptcha_challenge_field_holder'), @ready.bind @
|
return unless @isEnabled = !!container
|
||||||
ready: ->
|
|
||||||
setLifetime = (e) => @lifetime = e.detail
|
|
||||||
$.on window, 'captcha:timeout', setLifetime
|
|
||||||
$.globalEval 'window.dispatchEvent(new CustomEvent("captcha:timeout", {detail: RecaptchaState.timeout}))'
|
|
||||||
$.off window, 'captcha:timeout', setLifetime
|
|
||||||
|
|
||||||
imgContainer = $.el 'div',
|
imgContainer = $.el 'div',
|
||||||
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
|
||||||
@nodes =
|
@nodes =
|
||||||
challenge: $.id 'recaptcha_challenge_field_holder'
|
img: imgContainer.firstChild
|
||||||
img: imgContainer.firstChild
|
input: input
|
||||||
input: input
|
|
||||||
|
|
||||||
new MutationObserver(@load.bind @).observe @nodes.challenge,
|
$.on input, 'focus', @setup
|
||||||
childList: true
|
|
||||||
|
|
||||||
$.on imgContainer, 'click', @reload.bind @
|
|
||||||
$.on input, 'keydown', @keydown.bind @
|
|
||||||
$.get 'captchas', [], ({captchas}) =>
|
|
||||||
@sync captchas
|
|
||||||
$.sync 'captchas', @sync
|
|
||||||
# start with an uncached captcha
|
|
||||||
@reload()
|
|
||||||
|
|
||||||
<% if (type === 'userscript') { %>
|
<% if (type === 'userscript') { %>
|
||||||
# XXX Firefox lacks focusin/focusout support.
|
# XXX Firefox lacks focusin/focusout support.
|
||||||
@ -42,6 +29,35 @@ QR.captcha =
|
|||||||
|
|
||||||
$.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
|
||||||
|
@setupObserver.observe container, childList: true
|
||||||
|
setup: ->
|
||||||
|
$.globalEval 'loadRecaptcha()'
|
||||||
|
afterSetup: ->
|
||||||
|
return unless challenge = $.id 'recaptcha_challenge_field_holder'
|
||||||
|
QR.captcha.setupObserver.disconnect()
|
||||||
|
delete QR.captcha.setupObserver
|
||||||
|
|
||||||
|
setLifetime = (e) -> QR.captcha.lifetime = e.detail
|
||||||
|
$.on window, 'captcha:timeout', setLifetime
|
||||||
|
$.globalEval 'window.dispatchEvent(new CustomEvent("captcha:timeout", {detail: RecaptchaState.timeout}))'
|
||||||
|
$.off window, 'captcha:timeout', setLifetime
|
||||||
|
|
||||||
|
{img, input} = QR.captcha.nodes
|
||||||
|
img.parentNode.hidden = false
|
||||||
|
$.off input, 'focus', QR.captcha.setup
|
||||||
|
$.on input, 'keydown', QR.captcha.keydown.bind QR.captcha
|
||||||
|
$.on img.parentNode, 'click', QR.captcha.reload.bind QR.captcha
|
||||||
|
|
||||||
|
$.get 'captchas', [], ({captchas}) ->
|
||||||
|
QR.captcha.sync captchas
|
||||||
|
$.sync 'captchas', QR.captcha.sync
|
||||||
|
|
||||||
|
QR.captcha.nodes.challenge = challenge
|
||||||
|
new MutationObserver(QR.captcha.load.bind QR.captcha).observe challenge,
|
||||||
|
childList: true
|
||||||
|
QR.captcha.load()
|
||||||
sync: (captchas) ->
|
sync: (captchas) ->
|
||||||
QR.captcha.captchas = captchas
|
QR.captcha.captchas = captchas
|
||||||
QR.captcha.count()
|
QR.captcha.count()
|
||||||
@ -70,6 +86,7 @@ QR.captcha =
|
|||||||
@reload()
|
@reload()
|
||||||
$.set 'captchas', @captchas
|
$.set 'captchas', @captchas
|
||||||
clear: ->
|
clear: ->
|
||||||
|
return unless @captchas.length
|
||||||
now = Date.now()
|
now = Date.now()
|
||||||
for captcha, i in @captchas
|
for captcha, i in @captchas
|
||||||
break if captcha.timeout > now
|
break if captcha.timeout > now
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user