Integrate v1 captcha into current QR code.
This commit is contained in:
parent
60f0458ec3
commit
1892ad1973
@ -463,6 +463,11 @@ Config =
|
|||||||
'Use the non-Javascript fallback captcha in the QR even if Javascript is enabled.'
|
'Use the non-Javascript fallback captcha in the QR even if Javascript is enabled.'
|
||||||
1
|
1
|
||||||
]
|
]
|
||||||
|
'Use Recaptcha v1': [
|
||||||
|
false
|
||||||
|
'Use the old version of Recaptcha before the introduction of the checkbox.'
|
||||||
|
1
|
||||||
|
]
|
||||||
'Auto-load captcha': [
|
'Auto-load captcha': [
|
||||||
false
|
false
|
||||||
'Automatically load the captcha in the QR even if your post is empty.'
|
'Automatically load the captcha in the QR even if your post is empty.'
|
||||||
|
|||||||
@ -44,14 +44,31 @@ Captcha.v1 =
|
|||||||
|
|
||||||
@beforeSetup()
|
@beforeSetup()
|
||||||
@afterSetup() # reCAPTCHA might have loaded before the QR.
|
@afterSetup() # reCAPTCHA might have loaded before the QR.
|
||||||
|
|
||||||
|
cb:
|
||||||
|
focus: -> QR.captcha.setup false, true
|
||||||
|
|
||||||
beforeSetup: ->
|
beforeSetup: ->
|
||||||
{img, input} = @nodes
|
{img, input} = @nodes
|
||||||
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()
|
@count()
|
||||||
$.on input, 'focus', @setup
|
$.on input, 'focus click', @cb.focus
|
||||||
setup: ->
|
|
||||||
|
needed: ->
|
||||||
|
captchaCount = @captchas.length
|
||||||
|
captchaCount++ if QR.req
|
||||||
|
postsCount = QR.posts.length
|
||||||
|
postsCount = 0 if postsCount is 1 and !Conf['Auto-load captcha'] and !QR.posts[0].com and !QR.posts[0].file
|
||||||
|
captchaCount < postsCount
|
||||||
|
|
||||||
|
onNewPost: ->
|
||||||
|
|
||||||
|
onPostChange: ->
|
||||||
|
|
||||||
|
setup: (focus, force) ->
|
||||||
|
return unless @isEnabled and (@needed() or force)
|
||||||
$.globalEval '''
|
$.globalEval '''
|
||||||
(function() {
|
(function() {
|
||||||
var captchaContainer = document.getElementById("captchaContainer");
|
var captchaContainer = document.getElementById("captchaContainer");
|
||||||
@ -66,6 +83,8 @@ Captcha.v1 =
|
|||||||
setup();
|
setup();
|
||||||
})()
|
})()
|
||||||
'''
|
'''
|
||||||
|
@nodes.input.focus() if focus
|
||||||
|
|
||||||
afterSetup: ->
|
afterSetup: ->
|
||||||
return unless challenge = $.id 'recaptcha_challenge_field_holder'
|
return unless challenge = $.id 'recaptcha_challenge_field_holder'
|
||||||
return if challenge is QR.captcha.nodes.challenge
|
return if challenge is QR.captcha.nodes.challenge
|
||||||
@ -79,7 +98,7 @@ Captcha.v1 =
|
|||||||
img.parentNode.hidden = false
|
img.parentNode.hidden = false
|
||||||
input.placeholder = 'Verification'
|
input.placeholder = 'Verification'
|
||||||
QR.captcha.count()
|
QR.captcha.count()
|
||||||
$.off input, 'focus', QR.captcha.setup
|
$.off input, 'focus click', QR.captcha.cb.focus
|
||||||
|
|
||||||
QR.captcha.nodes.challenge = challenge
|
QR.captcha.nodes.challenge = challenge
|
||||||
new MutationObserver(QR.captcha.load.bind QR.captcha).observe challenge,
|
new MutationObserver(QR.captcha.load.bind QR.captcha).observe challenge,
|
||||||
@ -91,11 +110,13 @@ Captcha.v1 =
|
|||||||
if QR.nodes.el.getBoundingClientRect().bottom > doc.clientHeight
|
if QR.nodes.el.getBoundingClientRect().bottom > doc.clientHeight
|
||||||
QR.nodes.el.style.top = null
|
QR.nodes.el.style.top = null
|
||||||
QR.nodes.el.style.bottom = '0px'
|
QR.nodes.el.style.bottom = '0px'
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
|
return unless @isEnabled
|
||||||
$.globalEval 'Recaptcha.destroy()'
|
$.globalEval 'Recaptcha.destroy()'
|
||||||
@beforeSetup()
|
@beforeSetup()
|
||||||
|
|
||||||
sync: (captchas) ->
|
sync: (captchas=[]) ->
|
||||||
QR.captcha.captchas = captchas
|
QR.captcha.captchas = captchas
|
||||||
QR.captcha.count()
|
QR.captcha.count()
|
||||||
|
|
||||||
@ -109,10 +130,6 @@ Captcha.v1 =
|
|||||||
challenge = @nodes.img.alt
|
challenge = @nodes.img.alt
|
||||||
if response = @nodes.input.value
|
if response = @nodes.input.value
|
||||||
if Conf['Auto-load captcha'] then @reload() else @destroy()
|
if Conf['Auto-load captcha'] then @reload() else @destroy()
|
||||||
# Duplicate one-word captchas.
|
|
||||||
# Don't duplicate street numbers for now (needs testing).
|
|
||||||
if response and !/\s|^\d$/.test response
|
|
||||||
response = "#{response} #{response}"
|
|
||||||
{challenge, response}
|
{challenge, response}
|
||||||
|
|
||||||
save: ->
|
save: ->
|
||||||
|
|||||||
@ -10,8 +10,13 @@ QR =
|
|||||||
return if g.VIEW is 'archive'
|
return if g.VIEW is 'archive'
|
||||||
|
|
||||||
$.globalEval 'document.documentElement.dataset.jsEnabled = true;'
|
$.globalEval 'document.documentElement.dataset.jsEnabled = true;'
|
||||||
noscript = Conf['Force Noscript Captcha'] or !doc.dataset.jsEnabled
|
version = if Conf['Force Noscript Captcha'] or !doc.dataset.jsEnabled
|
||||||
@captcha = Captcha[if noscript then 'noscript' else 'v2']
|
'noscript'
|
||||||
|
else if Conf['Use Recaptcha v1']
|
||||||
|
'v1'
|
||||||
|
else
|
||||||
|
'v2'
|
||||||
|
@captcha = Captcha[version]
|
||||||
|
|
||||||
$.on d, '4chanXInitFinished', @initReady
|
$.on d, '4chanXInitFinished', @initReady
|
||||||
|
|
||||||
@ -654,7 +659,12 @@ QR =
|
|||||||
QR.status()
|
QR.status()
|
||||||
|
|
||||||
cb = (response) ->
|
cb = (response) ->
|
||||||
extra.form.append 'g-recaptcha-response', response if response?
|
if response?
|
||||||
|
if response.challenge?
|
||||||
|
extra.form.append 'recaptcha_challenge_field', response.challenge
|
||||||
|
extra.form.append 'recaptcha_response_field', response.response
|
||||||
|
else
|
||||||
|
extra.form.append 'g-recaptcha-response', response
|
||||||
QR.req = $.ajax "https://sys.4chan.org/#{g.BOARD}/post", options, extra
|
QR.req = $.ajax "https://sys.4chan.org/#{g.BOARD}/post", options, extra
|
||||||
QR.req.progress = '...'
|
QR.req.progress = '...'
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user