diff --git a/src/General/Main.coffee b/src/General/Main.coffee index b3af7e7f1..e5611f461 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -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] diff --git a/src/Posting/Captcha.fixes.coffee b/src/Posting/Captcha.fixes.coffee index c0c1df119..6f2cf6b14 100644 --- a/src/Posting/Captcha.fixes.coffee +++ b/src/Posting/Captcha.fixes.coffee @@ -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 diff --git a/src/Posting/Captcha.replace.coffee b/src/Posting/Captcha.replace.coffee index cbd58269d..d979c50ab 100644 --- a/src/Posting/Captcha.replace.coffee +++ b/src/Posting/Captcha.replace.coffee @@ -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 diff --git a/src/Posting/Captcha.v2.coffee b/src/Posting/Captcha.v2.coffee index 0541a1c46..22556c95b 100644 --- a/src/Posting/Captcha.v2.coffee +++ b/src/Posting/Captcha.v2.coffee @@ -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 '''