diff --git a/src/General/Settings/Advanced.html b/src/General/Settings/Advanced.html index 222bd7553..da511a032 100644 --- a/src/General/Settings/Advanced.html +++ b/src/General/Settings/Advanced.html @@ -54,6 +54,9 @@ API Key: +
+ +
diff --git a/src/Posting/Captcha.cache.coffee b/src/Posting/Captcha.cache.coffee index 2c2c12715..444e477ef 100644 --- a/src/Posting/Captcha.cache.coffee +++ b/src/Posting/Captcha.cache.coffee @@ -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: -> diff --git a/src/Posting/Captcha.v2.coffee b/src/Posting/Captcha.v2.coffee index 1908ed790..4b7e3565b 100644 --- a/src/Posting/Captcha.v2.coffee +++ b/src/Posting/Captcha.v2.coffee @@ -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 diff --git a/src/Posting/QR.post.coffee b/src/Posting/QR.post.coffee index c118006c0..d4cb4d8b4 100644 --- a/src/Posting/QR.post.coffee +++ b/src/Posting/QR.post.coffee @@ -167,6 +167,7 @@ QR.post = class QR.characterCount() @nodes.span.textContent = @com QR.captcha.moreNeeded() + Captcha.cache.prerequest() @rmErrored: (e) -> e.stopPropagation() diff --git a/src/config/Config.coffee b/src/config/Config.coffee index 12ac9b322..3c798ffd0 100644 --- a/src/config/Config.coffee +++ b/src/config/Config.coffee @@ -1184,3 +1184,5 @@ Config = cachedTitles: [[]] passMessageClosed: false + + 'Prerequest Captcha': false