diff --git a/package.json b/package.json index f62a0cbe2..08c34a967 100755 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "*://www.4chan.org/feedback", "https://www.google.com/recaptcha/api2/anchor?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*", "https://www.google.com/recaptcha/api2/frame?*&k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*", - "*://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*" + "*://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*", + "*://www.google.com/recaptcha/api/noscript?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*" ], "suffix": { "stable": "", diff --git a/src/General/Main.coffee b/src/General/Main.coffee index f52330270..5150d42f9 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -1,6 +1,9 @@ Main = init: -> if location.hostname is 'www.google.com' + if location.pathname is '/recaptcha/api/noscript' + $.ready -> Captcha.noscript.initFrame() + return if location.pathname is '/recaptcha/api/fallback' $.ready -> Captcha.v2.initFrame() $.get 'Captcha Fixes', true, ({'Captcha Fixes': enabled}) -> diff --git a/src/General/css/style.css b/src/General/css/style.css index 4e73484bc..525227a74 100755 --- a/src/General/css/style.css +++ b/src/General/css/style.css @@ -1239,10 +1239,13 @@ input.field.tripped:not(:hover):not(:focus) { min-height: 59px; min-width: 302px; } -.captcha-input{ +.captcha-input { width: 100%; margin: 1px 0 0; } +#qr.captcha-v1 #qr-captcha-iframe { + display: none; +} /* Recaptcha v2 */ #qr .captcha-root { @@ -1268,7 +1271,7 @@ input.field.tripped:not(:hover):not(:focus) { display: block; width: 100%; } -#qr-captcha-iframe { +#qr.captcha-v2 #qr-captcha-iframe { width: 302px; height: 423px; border: 0; diff --git a/src/Posting/Captcha.noscript.coffee b/src/Posting/Captcha.noscript.coffee index 1458c1f76..f9b03d8ae 100644 --- a/src/Posting/Captcha.noscript.coffee +++ b/src/Posting/Captcha.noscript.coffee @@ -1,6 +1,5 @@ Captcha.noscript = lifetime: 2 * $.MINUTE - iframeURL: '//www.google.com/recaptcha/api/fallback?k=<%= meta.recaptchaKey %>' init: -> return if d.cookie.indexOf('pass_enabled=1') >= 0 @@ -27,7 +26,7 @@ Captcha.noscript = token: @save.bind @ error: @error.bind @ - $.addClass QR.nodes.el, 'has-captcha' + $.addClass QR.nodes.el, 'has-captcha', 'captcha-v1', 'noscript-captcha' $.after QR.nodes.com.parentNode, [container, input] @captchas = [] @@ -42,12 +41,15 @@ Captcha.noscript = initFrame: -> conn = new Connection window.parent, "#{location.protocol}//boards.4chan.org", response: (response) -> - $.id('response').value = response - $('.fbc-challenge > form').submit() - conn.send - token: $('.fbc-verification-token > textarea')?.value - error: $('.fbc-error')?.textContent - return unless img = $ '.fbc-payload > img' + $.id('recaptcha_response_field').value = response + # The form has a field named 'submit' + HTMLFormElement.prototype.submit.call $('form') + if location.hash is '#response' + conn.send + token: $('textarea')?.value + error: $('.recaptcha_input_area')?.textContent.replace(/:$/, '') + return unless img = $ 'img' + $('form').action = '#response' cb = -> canvas = $.el 'canvas' canvas.width = img.width @@ -61,6 +63,12 @@ Captcha.noscript = timers: {} + iframeURL: -> + url = '//www.google.com/recaptcha/api/noscript?k=<%= meta.recaptchaKey %>' + if lang = Conf['captchaLanguage'].trim() + url += "&hl=#{encodeURIComponent lang}" + url + cb: focus: -> QR.captcha.setup false, true @@ -88,11 +96,11 @@ Captcha.noscript = if !@nodes.iframe @nodes.iframe = $.el 'iframe', id: 'qr-captcha-iframe' - src: @iframeURL - $.add d.body, @nodes.iframe + src: @iframeURL() + $.add QR.nodes.el, @nodes.iframe @conn.target = @nodes.iframe.contentWindow else if !@occupied or force - @nodes.iframe.src = @iframeURL + @nodes.iframe.src = @iframeURL() @occupied = true @nodes.input.focus() if focus @@ -125,7 +133,7 @@ Captcha.noscript = if captcha = @captchas.shift() @count() $.set 'captchas', @captchas - captcha.response + {challenge: captcha.response, response: 'manual_challenge'} else if /\S/.test @nodes.input.value (cb) => @submitCB = cb @@ -142,7 +150,7 @@ Captcha.noscript = delete @occupied @nodes.input.value = '' if @submitCB - @submitCB token + @submitCB {challenge: token, response: 'manual_challenge'} delete @submitCB if @needed() then @reload() else @destroy() else @@ -212,7 +220,7 @@ Captcha.noscript = @destroy() reload: -> - @nodes.iframe.src = @iframeURL + @nodes.iframe.src = @iframeURL() @occupied = true @nodes.img?.hidden = true diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 71c81fdc2..9bb9877b2 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -9,7 +9,11 @@ QR = return if g.VIEW is 'archive' - version = if Conf['Use Recaptcha v1'] then 'v1' else 'v2' + version = if Conf['Use Recaptcha v1'] + noscript = Conf['Force Noscript Captcha'] or not $.hasClass doc, 'js-enabled' + if noscript then 'noscript' else 'v1' + else + 'v2' @captcha = Captcha[version] $.on d, '4chanXInitFinished', @initReady