Add option to request captcha from captcha services when you start typing.

This commit is contained in:
ccd0 2019-09-05 18:29:51 -07:00
parent 95c66ee153
commit 6a3f0f44bb
5 changed files with 35 additions and 5 deletions

View File

@ -54,6 +54,9 @@
API Key: <input name="captchaServiceKey" class="field" spellcheck="false">
<datalist id="list-captchaServiceDomain"></datalist>
</div>
<div>
<label><input type="checkbox" name="Prerequest Captcha"> Request captcha when you start typing. Quicker but may result some captchas expiring and being wasted.</label>
</div>
</fieldset>
<fieldset>

View File

@ -10,19 +10,39 @@ Captcha.cache =
getCount: ->
@captchas.length
needed: ->
neededRaw: ->
not (
@haveCookie() or @captchas.length or QR.req
@haveCookie() or @captchas.length or QR.req or @submitCB
) and (
QR.posts.length > 1 or Conf['Auto-load captcha'] or /^\s*[^\s>]/m.test(QR.posts[0].com or '') or QR.posts[0].file
) and (
@submitCB or $.event('LoadCaptcha')
)
needed: ->
@neededRaw() and $.event('LoadCaptcha')
prerequest: ->
return unless Conf['Prerequest Captcha']
# Post count temporarily off by 1 when called from QR.post.rm, QR.close, or QR.submit
$.queueTask =>
if (
!@prerequested and
@neededRaw() and
!$.event('LoadCaptcha') and
!QR.captcha.occupied() and
QR.cooldown.seconds <= 60 and
QR.selected is QR.posts[QR.posts.length - 1] and
/^\s*[^\s>]/m.test(QR.selected.com or '')
)
isReply = (QR.selected.thread isnt 'new')
if !$.event('RequestCaptcha', {isReply})
@prerequested = true
@submitCB = @save.bind(@)
haveCookie: ->
/\b_ct=/.test(d.cookie) and QR.posts[0].thread isnt 'new'
getOne: ->
delete @prerequested
@clear()
if (captcha = @captchas.shift())
@count()
@ -31,7 +51,8 @@ Captcha.cache =
null
request: (isReply) ->
return if $.event('RequestCaptcha', {isReply})
if !@submitCB
return if $.event('RequestCaptcha', {isReply})
(cb) => @submitCB = cb
abort: ->

View File

@ -192,3 +192,6 @@ Captcha.v2 =
$.global ->
container = document.querySelector '#qr .captcha-container'
window.grecaptcha.reset container.dataset.widgetID
occupied: ->
!!@nodes.container and !@timeouts.destroy

View File

@ -167,6 +167,7 @@ QR.post = class
QR.characterCount()
@nodes.span.textContent = @com
QR.captcha.moreNeeded()
Captcha.cache.prerequest()
@rmErrored: (e) ->
e.stopPropagation()

View File

@ -1184,3 +1184,5 @@ Config =
cachedTitles: [[]]
passMessageClosed: false
'Prerequest Captcha': false