Improve conditions for loading v2 captcha when more captchas are needed.

This commit is contained in:
ccd0 2017-02-06 15:07:54 -08:00
parent 136b7d5666
commit af7b158846
3 changed files with 16 additions and 19 deletions

View File

@ -101,9 +101,7 @@ Captcha.v1 =
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: ->
moreNeeded: ->
setup: (focus, force) ->
return unless @isEnabled and (force or @needed())

View File

@ -34,7 +34,7 @@ Captcha.v2 =
$.queueTask => @save false
timeouts: {}
postsCount: 0
prevNeeded: 0
noscriptURL: ->
url = 'https://www.google.com/recaptcha/api/fallback?k=<%= meta.recaptchaKey %>'
@ -45,16 +45,17 @@ Captcha.v2 =
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
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: ->
@setup()
onPostChange: ->
@setup() if @postsCount is 0
@postsCount = 0 if QR.posts.length is 1 and !Conf['Auto-load captcha'] and !QR.posts[0].com and !QR.posts[0].file
moreNeeded: ->
# Post count temporarily off by 1 when called from QR.post.rm, QR.close, or QR.submit
$.queueTask =>
needed = @needed()
if needed and not @prevNeeded
@setup(QR.cooldown.auto and d.activeElement is QR.nodes.status)
@prevNeeded = needed
toggle: ->
if @nodes.container and !@timeouts.destroy
@ -215,10 +216,10 @@ Captcha.v2 =
@captchas = @captchas[i..]
@count()
$.set 'captchas', @captchas
@setup(d.activeElement is QR.nodes.status)
count: ->
@nodes.counter.textContent = "Captchas: #{@captchas.length}"
@moreNeeded()
clearTimeout @timeouts.clear
if @captchas.length
@timeouts.clear = setTimeout @clear.bind(@), @captchas[0].timeout - Date.now()

View File

@ -57,8 +57,7 @@ QR.post = class
(@load() if QR.selected is @) # load persona
@select() if select
@unlock()
# Post count temporarily off by 1 when called from QR.post.rm or QR.close
$.queueTask -> QR.captcha.onNewPost()
QR.captcha.moreNeeded()
rm: ->
@delete()
@ -161,8 +160,7 @@ QR.post = class
if @ is QR.selected
QR.characterCount()
@nodes.span.textContent = @com
# Post count temporarily off by 1 when called from QR.post.rm or QR.close
$.queueTask -> QR.captcha.onPostChange()
QR.captcha.moreNeeded()
@rmErrored: (e) ->
e.stopPropagation()
@ -203,7 +201,7 @@ QR.post = class
@filesize = $.bytesToString @file.size
@checkSize()
$.addClass @nodes.el, 'has-file'
$.queueTask -> QR.captcha.onPostChange()
QR.captcha.moreNeeded()
URL.revokeObjectURL @URL
@saveFilename()
if @ is QR.selected