Improve accuracy of determining that comment is only a quote and thus captcha should not be opened yet. #2421, #2431

This commit is contained in:
ccd0 2019-09-11 21:22:41 -07:00
parent 4ecee3fa1a
commit 582edf9442
3 changed files with 11 additions and 2 deletions

View File

@ -14,7 +14,7 @@ Captcha.cache =
not ( not (
@haveCookie() or @captchas.length or QR.req or @submitCB @haveCookie() or @captchas.length or QR.req or @submitCB
) and ( ) 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 QR.posts.length > 1 or Conf['Auto-load captcha'] or !QR.posts[0].isOnlyQuotes() or QR.posts[0].file
) )
needed: -> needed: ->
@ -31,7 +31,7 @@ Captcha.cache =
!QR.captcha.occupied() and !QR.captcha.occupied() and
QR.cooldown.seconds <= 60 and QR.cooldown.seconds <= 60 and
QR.selected is QR.posts[QR.posts.length - 1] and QR.selected is QR.posts[QR.posts.length - 1] and
/^\s*[^\s>]/m.test(QR.selected.com or '') !QR.selected.isOnlyQuotes()
) )
isReply = (QR.selected.thread isnt 'new') isReply = (QR.selected.thread isnt 'new')
if !$.event('RequestCaptcha', {isReply}) if !$.event('RequestCaptcha', {isReply})

View File

@ -329,6 +329,8 @@ QR =
{com, thread} = QR.nodes {com, thread} = QR.nodes
thread.value = Get.threadFromNode @ unless com.value thread.value = Get.threadFromNode @ unless com.value
wasOnlyQuotes = QR.selected.isOnlyQuotes()
caretPos = com.selectionStart caretPos = com.selectionStart
# Replace selection for text. # Replace selection for text.
com.value = com.value[...caretPos] + text + com.value[com.selectionEnd..] com.value = com.value[...caretPos] + text + com.value[com.selectionEnd..]
@ -337,6 +339,9 @@ QR =
com.setSelectionRange range, range com.setSelectionRange range, range
com.focus() com.focus()
# This allows us to determine if any text other than quotes has been typed.
QR.selected.quotedText = com.value if wasOnlyQuotes
QR.selected.save com QR.selected.save com
QR.selected.save thread QR.selected.save thread
@ -654,6 +659,7 @@ QR =
return return
post = QR.posts[0] post = QR.posts[0]
delete post.quotedText
post.forceSave() post.forceSave()
threadID = post.thread threadID = post.thread
thread = g.BOARD.threads.get(threadID) thread = g.BOARD.threads.get(threadID)

View File

@ -169,6 +169,9 @@ QR.post = class
QR.captcha.moreNeeded() QR.captcha.moreNeeded()
Captcha.cache.prerequest() Captcha.cache.prerequest()
isOnlyQuotes: ->
(@com or '').trim() is (@quotedText or '').trim()
@rmErrored: (e) -> @rmErrored: (e) ->
e.stopPropagation() e.stopPropagation()
for post in QR.posts by -1 when errors = post.errors for post in QR.posts by -1 when errors = post.errors