Support captcha code copying on all forms.

This commit is contained in:
ccd0 2015-11-20 04:12:40 -08:00
parent 720998721b
commit a49580e6be
4 changed files with 32 additions and 21 deletions

View File

@ -8,8 +8,6 @@ Main =
window['<%= meta.name %> antidup'] = true
if location.hostname is 'www.google.com'
if location.pathname is '/recaptcha/api/fallback'
$.ready -> Captcha.v2.initFrame()
$.get 'Captcha Fixes', true, ({'Captcha Fixes': enabled}) ->
if enabled
$.ready -> Captcha.fixes.init()
@ -353,7 +351,7 @@ Main =
features: [
['Polyfill', Polyfill]
['Normalize URL', NormalizeURL]
['Captcha Replacement', Captcha.replace]
['Captcha Configuration', Captcha.replace]
['Redirect', Redirect]
['Header', Header]
['Catalog Links', CatalogLinks]

View File

@ -54,6 +54,9 @@ Captcha.fixes =
$.on d, 'keydown', @keybinds.bind(@)
initNoscript: ->
data = if (token = $('.fbc-verification-token > textarea')?.value) then {token} else {working: true}
new Connection(window.parent, '*').send data
@noscript = true
@images = $$ '.fbc-payload-imageselect > input'
return unless @images.length is 9

View File

@ -15,7 +15,7 @@ Captcha.replace =
$.ready Captcha.replace.v1
return
if Conf['captchaLanguage'].trim()
if Conf['captchaLanguage'].trim() or Conf['Captcha Fixes']
if location.hostname is 'boards.4chan.org'
$.onExists doc, '#captchaFormPart', true, (node) -> $.onExists node, 'iframe', true, Captcha.replace.iframe
else
@ -54,11 +54,26 @@ Captcha.replace =
script = $.el 'script',
src: url
$.add d.head, script
$.onExists d.body, 'iframe', true, Captcha.replace.autocopy
iframe: (el) ->
return unless (lang = Conf['captchaLanguage'].trim())
src = if /[?&]hl=/.test el.src
el.src.replace(/([?&]hl=)[^&]*/, '$1' + encodeURIComponent lang)
else
el.src + "&hl=#{encodeURIComponent lang}"
el.src = src unless el.src is src
iframe: (iframe) ->
if (lang = Conf['captchaLanguage'].trim())
src = if /[?&]hl=/.test iframe.src
iframe.src.replace(/([?&]hl=)[^&]*/, '$1' + encodeURIComponent lang)
else
iframe.src + "&hl=#{encodeURIComponent lang}"
iframe.src = src unless iframe.src is src
Captcha.replace.autocopy iframe
autocopy: (iframe) ->
return unless Conf['Captcha Fixes'] and /^https:\/\/www\.google\.com\/recaptcha\/api\/fallback\?/.test(iframe.src)
new Connection iframe, 'https://www.google.com',
working: ->
if $.id('qr')?.contains iframe
$('#qr .captcha-container textarea')?.parentNode.hidden = true
token: (token) ->
node = iframe
while (node = node.parentNode)
break if (textarea = $ 'textarea', node)
textarea.value = token
$.event 'input', null, textarea

View File

@ -6,8 +6,6 @@ Captcha.v2 =
return unless (@isEnabled = !!$ '#g-recaptcha, #captchaContainerAlt')
if (@noscript = Conf['Force Noscript Captcha'] or not Main.jsEnabled)
@conn = new Connection null, "#{location.protocol}//www.google.com",
token: (token) => @save true, token
$.addClass QR.nodes.el, 'noscript-captcha'
@captchas = []
@ -37,16 +35,11 @@ Captcha.v2 =
new MutationObserver(@watchBubbles.bind @).observe d.body,
childList: true
initFrame: ->
if (token = $('.fbc-verification-token > textarea')?.value)
conn = new Connection window.parent, "#{location.protocol}//boards.4chan.org"
conn.send {token}
timeouts: {}
postsCount: 0
noscriptURL: ->
url = '//www.google.com/recaptcha/api/fallback?k=<%= meta.recaptchaKey %>'
url = 'https://www.google.com/recaptcha/api/fallback?k=<%= meta.recaptchaKey %>'
if (lang = Conf['captchaLanguage'].trim())
url += "&hl=#{encodeURIComponent lang}"
url
@ -100,8 +93,10 @@ Captcha.v2 =
iframe = $.el 'iframe',
id: 'qr-captcha-iframe'
src: @noscriptURL()
$.add @nodes.container, iframe
@conn.target = iframe
div = $.el 'div'
textarea = $.el 'textarea'
$.add div, textarea
$.add @nodes.container, [iframe, div]
setupJS: ->
$.globalEval '''