Implement v1 noscript captcha.

This commit is contained in:
ccd0 2015-06-21 13:11:08 -07:00
parent 0a97248c99
commit b937825747
5 changed files with 37 additions and 18 deletions

View File

@ -25,7 +25,8 @@
"*://www.4chan.org/feedback", "*://www.4chan.org/feedback",
"https://www.google.com/recaptcha/api2/anchor?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*", "https://www.google.com/recaptcha/api2/anchor?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*",
"https://www.google.com/recaptcha/api2/frame?*&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": { "suffix": {
"stable": "", "stable": "",

View File

@ -1,6 +1,9 @@
Main = Main =
init: -> init: ->
if location.hostname is 'www.google.com' 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' if location.pathname is '/recaptcha/api/fallback'
$.ready -> Captcha.v2.initFrame() $.ready -> Captcha.v2.initFrame()
$.get 'Captcha Fixes', true, ({'Captcha Fixes': enabled}) -> $.get 'Captcha Fixes', true, ({'Captcha Fixes': enabled}) ->

View File

@ -1239,10 +1239,13 @@ input.field.tripped:not(:hover):not(:focus) {
min-height: 59px; min-height: 59px;
min-width: 302px; min-width: 302px;
} }
.captcha-input{ .captcha-input {
width: 100%; width: 100%;
margin: 1px 0 0; margin: 1px 0 0;
} }
#qr.captcha-v1 #qr-captcha-iframe {
display: none;
}
/* Recaptcha v2 */ /* Recaptcha v2 */
#qr .captcha-root { #qr .captcha-root {
@ -1268,7 +1271,7 @@ input.field.tripped:not(:hover):not(:focus) {
display: block; display: block;
width: 100%; width: 100%;
} }
#qr-captcha-iframe { #qr.captcha-v2 #qr-captcha-iframe {
width: 302px; width: 302px;
height: 423px; height: 423px;
border: 0; border: 0;

View File

@ -1,6 +1,5 @@
Captcha.noscript = Captcha.noscript =
lifetime: 2 * $.MINUTE lifetime: 2 * $.MINUTE
iframeURL: '//www.google.com/recaptcha/api/fallback?k=<%= meta.recaptchaKey %>'
init: -> init: ->
return if d.cookie.indexOf('pass_enabled=1') >= 0 return if d.cookie.indexOf('pass_enabled=1') >= 0
@ -27,7 +26,7 @@ Captcha.noscript =
token: @save.bind @ token: @save.bind @
error: @error.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] $.after QR.nodes.com.parentNode, [container, input]
@captchas = [] @captchas = []
@ -42,12 +41,15 @@ Captcha.noscript =
initFrame: -> initFrame: ->
conn = new Connection window.parent, "#{location.protocol}//boards.4chan.org", conn = new Connection window.parent, "#{location.protocol}//boards.4chan.org",
response: (response) -> response: (response) ->
$.id('response').value = response $.id('recaptcha_response_field').value = response
$('.fbc-challenge > form').submit() # The form has a field named 'submit'
conn.send HTMLFormElement.prototype.submit.call $('form')
token: $('.fbc-verification-token > textarea')?.value if location.hash is '#response'
error: $('.fbc-error')?.textContent conn.send
return unless img = $ '.fbc-payload > img' token: $('textarea')?.value
error: $('.recaptcha_input_area')?.textContent.replace(/:$/, '')
return unless img = $ 'img'
$('form').action = '#response'
cb = -> cb = ->
canvas = $.el 'canvas' canvas = $.el 'canvas'
canvas.width = img.width canvas.width = img.width
@ -61,6 +63,12 @@ Captcha.noscript =
timers: {} timers: {}
iframeURL: ->
url = '//www.google.com/recaptcha/api/noscript?k=<%= meta.recaptchaKey %>'
if lang = Conf['captchaLanguage'].trim()
url += "&hl=#{encodeURIComponent lang}"
url
cb: cb:
focus: -> QR.captcha.setup false, true focus: -> QR.captcha.setup false, true
@ -88,11 +96,11 @@ Captcha.noscript =
if !@nodes.iframe if !@nodes.iframe
@nodes.iframe = $.el 'iframe', @nodes.iframe = $.el 'iframe',
id: 'qr-captcha-iframe' id: 'qr-captcha-iframe'
src: @iframeURL src: @iframeURL()
$.add d.body, @nodes.iframe $.add QR.nodes.el, @nodes.iframe
@conn.target = @nodes.iframe.contentWindow @conn.target = @nodes.iframe.contentWindow
else if !@occupied or force else if !@occupied or force
@nodes.iframe.src = @iframeURL @nodes.iframe.src = @iframeURL()
@occupied = true @occupied = true
@nodes.input.focus() if focus @nodes.input.focus() if focus
@ -125,7 +133,7 @@ Captcha.noscript =
if captcha = @captchas.shift() if captcha = @captchas.shift()
@count() @count()
$.set 'captchas', @captchas $.set 'captchas', @captchas
captcha.response {challenge: captcha.response, response: 'manual_challenge'}
else if /\S/.test @nodes.input.value else if /\S/.test @nodes.input.value
(cb) => (cb) =>
@submitCB = cb @submitCB = cb
@ -142,7 +150,7 @@ Captcha.noscript =
delete @occupied delete @occupied
@nodes.input.value = '' @nodes.input.value = ''
if @submitCB if @submitCB
@submitCB token @submitCB {challenge: token, response: 'manual_challenge'}
delete @submitCB delete @submitCB
if @needed() then @reload() else @destroy() if @needed() then @reload() else @destroy()
else else
@ -212,7 +220,7 @@ Captcha.noscript =
@destroy() @destroy()
reload: -> reload: ->
@nodes.iframe.src = @iframeURL @nodes.iframe.src = @iframeURL()
@occupied = true @occupied = true
@nodes.img?.hidden = true @nodes.img?.hidden = true

View File

@ -9,7 +9,11 @@ QR =
return if g.VIEW is 'archive' 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] @captcha = Captcha[version]
$.on d, '4chanXInitFinished', @initReady $.on d, '4chanXInitFinished', @initReady