dummy captcha response input

This commit is contained in:
James Campos 2011-08-24 00:12:55 -07:00
parent 97565c3552
commit 93efd42880
2 changed files with 42 additions and 54 deletions

View File

@ -1262,42 +1262,39 @@
} }
}, },
captchaNode: function(e) { captchaNode: function(e) {
var target;
if (!qr.el) { if (!qr.el) {
return; return;
} }
target = e.target; val = e.target.value;
$('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=" + target.value; $('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=" + val;
$('#recaptcha_challenge_field', qr.el).value = target.value; qr.challenge = val;
return qr.captchaTime = Date.now(); return qr.captchaTime = Date.now();
}, },
captchaKeydown: function(e) { captchaKeydown: function(e) {
var blank, captchas; var captchas;
if (!(e.keyCode === 13 && this.value)) { if (!(e.keyCode === 13 && this.value)) {
return; return;
} }
blank = !$('textarea', qr.el).value && !$('input[type=file]', qr.el).files.length;
if (!(blank || cooldown.duration)) {
return;
}
e.preventDefault();
captchas = $.get('captchas', []); captchas = $.get('captchas', []);
captchas.push({ captchas.push({
challenge: $('#recaptcha_challenge_field', qr.el).value, challenge: qr.challenge,
response: this.value, response: this.value,
time: qr.captchaTime time: qr.captchaTime
}); });
$.set('captchas', captchas); $.set('captchas', captchas);
this.nextSibling.textContent = captchas.length + ' captchas'; $('#captchas', qr.el).textContent = captchas.length + ' captchas';
Recaptcha.reload(); Recaptcha.reload();
return this.value = ''; this.value = '';
if (!$('textarea', qr.el).value && !$('input[type=file]', qr.el).files.length) {
return e.preventDefault();
}
}, },
close: function() { close: function() {
$.rm(qr.el); $.rm(qr.el);
return qr.el = null; return qr.el = null;
}, },
dialog: function(link) { dialog: function(link) {
var THREAD_ID, c, challenge, email, html, m, name, pwd, spoiler, submitDisabled, submitValue; var THREAD_ID, c, email, html, m, name, pwd, spoiler, submitDisabled, submitValue;
c = d.cookie; c = d.cookie;
name = (m = c.match(/4chan_name=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; name = (m = c.match(/4chan_name=([^;]+)/)) ? decodeURIComponent(m[1]) : '';
email = (m = c.match(/4chan_email=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; email = (m = c.match(/4chan_email=([^;]+)/)) ? decodeURIComponent(m[1]) : '';
@ -1306,8 +1303,8 @@
submitDisabled = $('#com_submit').disabled ? 'disabled' : ''; submitDisabled = $('#com_submit').disabled ? 'disabled' : '';
THREAD_ID = g.THREAD_ID || $.x('ancestor::div[@class="thread"]/div', link).id; THREAD_ID = g.THREAD_ID || $.x('ancestor::div[@class="thread"]/div', link).id;
spoiler = $('.postarea label') ? '<label> [<input type=checkbox name=spoiler>Spoiler Image?]</label>' : ''; spoiler = $('.postarea label') ? '<label> [<input type=checkbox name=spoiler>Spoiler Image?]</label>' : '';
challenge = $('#recaptcha_challenge_field').value; qr.challenge = $('#recaptcha_challenge_field').value;
html = " <a id=close title=close>X</a> <input type=checkbox id=autohide title=autohide> <div class=move> <input class=inputtext type=text name=name value='" + name + "' placeholder=Name form=qr_form> Quick Reply </div> <div class=autohide> <form name=post action=http://sys.4chan.org/" + g.BOARD + "/post method=POST enctype=multipart/form-data target=iframe id=qr_form> <input type=hidden name=resto value=" + THREAD_ID + "> <input type=hidden name=recaptcha_challenge_field id=recaptcha_challenge_field value=" + challenge + "> <input type=hidden name=mode value=regist> <div><input class=inputtext type=text name=email value='" + email + "' placeholder=E-mail>" + spoiler + "</div> <div><input class=inputtext type=text name=sub placeholder=Subject><input type=submit value=" + submitValue + " id=com_submit " + submitDisabled + "><label><input type=checkbox id=auto>auto</label></div> <div><textarea class=inputtext name=com placeholder=Comment></textarea></div> <div><img src=http://www.google.com/recaptcha/api/image?c=" + challenge + "></div> <div><input class=inputtext type=text name=recaptcha_response_field placeholder=Verification autocomplete=off id=recaptcha_response_field><span class=captcha>" + ($.get('captchas', []).length) + " captchas</span></div> <div><input type=file name=upfile></div> </form> <div id=files></div> <div><input class=inputtext type=password name=pwd value='" + pwd + "' placeholder=Password form=qr_form maxlength=8><a id=attach>attach another file</a></div> </div> <a id=error class=error></a> "; html = " <a id=close title=close>X</a> <input type=checkbox id=autohide title=autohide> <div class=move> <input class=inputtext type=text name=name value='" + name + "' placeholder=Name form=qr_form> Quick Reply </div> <div class=autohide> <form name=post action=http://sys.4chan.org/" + g.BOARD + "/post method=POST enctype=multipart/form-data target=iframe id=qr_form> <input type=hidden name=resto value=" + THREAD_ID + "> <input type=hidden name=recaptcha_challenge_field id=recaptcha_challenge_field> <input type=hidden name=mode value=regist> <div><input class=inputtext type=text name=email value='" + email + "' placeholder=E-mail>" + spoiler + "</div> <div><input class=inputtext type=text name=sub placeholder=Subject><input type=submit value=" + submitValue + " id=com_submit " + submitDisabled + "><label><input type=checkbox id=auto>auto</label></div> <div><textarea class=inputtext name=com placeholder=Comment></textarea></div> <div><img src=http://www.google.com/recaptcha/api/image?c=" + qr.challenge + "></div> <div><input class=inputtext type=text autocomplete=off placeholder=Verification id=dummy><input type=hidden name=recaptcha_response_field id=recaptcha_response_field><span id=captchas>" + ($.get('captchas', []).length) + " captchas</span></div> <div><input type=file name=upfile></div> </form> <div id=files></div> <div><input class=inputtext type=password name=pwd value='" + pwd + "' placeholder=Password form=qr_form maxlength=8><a id=attach>attach another file</a></div> </div> <a id=error class=error></a> ";
qr.el = ui.dialog('qr', { qr.el = ui.dialog('qr', {
top: '0px', top: '0px',
left: '0px' left: '0px'
@ -1320,8 +1317,8 @@
$.bind($('form', qr.el), 'submit', qr.submit); $.bind($('form', qr.el), 'submit', qr.submit);
$.bind($('#attach', qr.el), 'click', qr.attach); $.bind($('#attach', qr.el), 'click', qr.attach);
$.bind($('img', qr.el), 'click', Recaptcha.reload); $.bind($('img', qr.el), 'click', Recaptcha.reload);
$.bind($('#recaptcha_response_field', qr.el), 'keydown', Recaptcha.listener); $.bind($('#dummy', qr.el), 'keydown', Recaptcha.listener);
$.bind($('#recaptcha_response_field', qr.el), 'keydown', qr.captchaKeydown); $.bind($('#dummy', qr.el), 'keydown', qr.captchaKeydown);
return $.append(d.body, qr.el); return $.append(d.body, qr.el);
}, },
message: function(e) { message: function(e) {
@ -1366,15 +1363,11 @@
return $.bind(quote, 'click', qr.quote); return $.bind(quote, 'click', qr.quote);
}, },
postInvalid: function() { postInvalid: function() {
var captcha, captchas, content, cutoff, responseField; var captcha, captchas, content, cutoff;
content = $('textarea', qr.el).value || $('input[type=file]', qr.el).files.length; content = $('textarea', qr.el).value || $('input[type=file]', qr.el).files.length;
if (!content) { if (!content) {
return 'Error: No text entered.'; return 'Error: No text entered.';
} }
responseField = $('#recaptcha_response_field', qr.el);
if (responseField.value) {
return;
}
/* /*
captchas expire after 5 hours (couldn't find an official source, so captchas expire after 5 hours (couldn't find an official source, so
anonymous empirically verified). cutoff 5 minutes before then, b/c posting anonymous empirically verified). cutoff 5 minutes before then, b/c posting
@ -1388,12 +1381,12 @@
} }
} }
$.set('captchas', captchas); $.set('captchas', captchas);
responseField.nextSibling.textContent = captchas.length + ' captchas'; $('#captchas', qr.el).textContent = captchas.length + ' captchas';
if (!captcha) { if (!captcha) {
return 'You forgot to type in the verification.'; return 'You forgot to type in the verification.';
} }
$('#recaptcha_challenge_field', qr.el).value = captcha.challenge; $('#recaptcha_challenge_field', qr.el).value = captcha.challenge;
responseField.value = captcha.response; $('#recaptcha_response_field', qr.el).value = captcha.response;
return false; return false;
}, },
quote: function(e) { quote: function(e) {
@ -1438,7 +1431,7 @@
e.preventDefault(); e.preventDefault();
alert(msg); alert(msg);
if (msg === 'You forgot to type in the verification.') { if (msg === 'You forgot to type in the verification.') {
$('#recaptcha_response_field', qr.el).focus(); $('#dummy', qr.el).focus();
} }
return; return;
} }

View File

@ -1001,29 +1001,27 @@ qr =
captchaNode: (e) -> captchaNode: (e) ->
return unless qr.el return unless qr.el
{target} = e val = e.target.value
$('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=" + target.value $('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=" + val
$('#recaptcha_challenge_field', qr.el).value = target.value qr.challenge = val
qr.captchaTime = Date.now() qr.captchaTime = Date.now()
captchaKeydown: (e) -> captchaKeydown: (e) ->
return unless e.keyCode is 13 and @value #enter, captcha filled return unless e.keyCode is 13 and @value #enter, captcha filled
blank = !$('textarea', qr.el).value and !$('input[type=file]', qr.el).files.length
return unless blank or cooldown.duration
e.preventDefault()
captchas = $.get 'captchas', [] captchas = $.get 'captchas', []
captchas.push captchas.push
challenge: $('#recaptcha_challenge_field', qr.el).value challenge: qr.challenge
response: @value response: @value
time: qr.captchaTime time: qr.captchaTime
$.set 'captchas', captchas $.set 'captchas', captchas
@nextSibling.textContent = captchas.length + ' captchas' $('#captchas', qr.el).textContent = captchas.length + ' captchas'
Recaptcha.reload() Recaptcha.reload()
@value = '' @value = ''
if !$('textarea', qr.el).value and !$('input[type=file]', qr.el).files.length
e.preventDefault()
close: -> close: ->
$.rm qr.el $.rm qr.el
qr.el = null qr.el = null
@ -1038,7 +1036,7 @@ qr =
#FIXME inlined cross-thread quotes #FIXME inlined cross-thread quotes
THREAD_ID = g.THREAD_ID or $.x('ancestor::div[@class="thread"]/div', link).id THREAD_ID = g.THREAD_ID or $.x('ancestor::div[@class="thread"]/div', link).id
spoiler = if $('.postarea label') then '<label> [<input type=checkbox name=spoiler>Spoiler Image?]</label>' else '' spoiler = if $('.postarea label') then '<label> [<input type=checkbox name=spoiler>Spoiler Image?]</label>' else ''
challenge = $('#recaptcha_challenge_field').value qr.challenge = $('#recaptcha_challenge_field').value
html = " html = "
<a id=close title=close>X</a> <a id=close title=close>X</a>
@ -1050,13 +1048,13 @@ qr =
<div class=autohide> <div class=autohide>
<form name=post action=http://sys.4chan.org/#{g.BOARD}/post method=POST enctype=multipart/form-data target=iframe id=qr_form> <form name=post action=http://sys.4chan.org/#{g.BOARD}/post method=POST enctype=multipart/form-data target=iframe id=qr_form>
<input type=hidden name=resto value=#{THREAD_ID}> <input type=hidden name=resto value=#{THREAD_ID}>
<input type=hidden name=recaptcha_challenge_field id=recaptcha_challenge_field value=#{challenge}> <input type=hidden name=recaptcha_challenge_field id=recaptcha_challenge_field>
<input type=hidden name=mode value=regist> <input type=hidden name=mode value=regist>
<div><input class=inputtext type=text name=email value='#{email}' placeholder=E-mail>#{spoiler}</div> <div><input class=inputtext type=text name=email value='#{email}' placeholder=E-mail>#{spoiler}</div>
<div><input class=inputtext type=text name=sub placeholder=Subject><input type=submit value=#{submitValue} id=com_submit #{submitDisabled}><label><input type=checkbox id=auto>auto</label></div> <div><input class=inputtext type=text name=sub placeholder=Subject><input type=submit value=#{submitValue} id=com_submit #{submitDisabled}><label><input type=checkbox id=auto>auto</label></div>
<div><textarea class=inputtext name=com placeholder=Comment></textarea></div> <div><textarea class=inputtext name=com placeholder=Comment></textarea></div>
<div><img src=http://www.google.com/recaptcha/api/image?c=#{challenge}></div> <div><img src=http://www.google.com/recaptcha/api/image?c=#{qr.challenge}></div>
<div><input class=inputtext type=text name=recaptcha_response_field placeholder=Verification autocomplete=off id=recaptcha_response_field><span class=captcha>#{$.get('captchas', []).length} captchas</span></div> <div><input class=inputtext type=text autocomplete=off placeholder=Verification id=dummy><input type=hidden name=recaptcha_response_field id=recaptcha_response_field><span id=captchas>#{$.get('captchas', []).length} captchas</span></div>
<div><input type=file name=upfile></div> <div><input type=file name=upfile></div>
</form> </form>
<div id=files></div> <div id=files></div>
@ -1066,14 +1064,14 @@ qr =
" "
qr.el = ui.dialog 'qr', top: '0px', left: '0px', html qr.el = ui.dialog 'qr', top: '0px', left: '0px', html
$.bind $('input[name=name]', qr.el), 'mousedown', (e) -> e.stopPropagation() $.bind $('input[name=name]', qr.el), 'mousedown', (e) -> e.stopPropagation()
$.bind $('input[name=upfile]', qr.el), 'change', qr.validateFileSize $.bind $('input[name=upfile]', qr.el), 'change', qr.validateFileSize
$.bind $('#close', qr.el), 'click', qr.close $.bind $('#close', qr.el), 'click', qr.close
$.bind $('form', qr.el), 'submit', qr.submit $.bind $('form', qr.el), 'submit', qr.submit
$.bind $('#attach', qr.el), 'click', qr.attach $.bind $('#attach', qr.el), 'click', qr.attach
$.bind $('img', qr.el), 'click', Recaptcha.reload $.bind $('img', qr.el), 'click', Recaptcha.reload
$.bind $('#recaptcha_response_field', qr.el), 'keydown', Recaptcha.listener $.bind $('#dummy', qr.el), 'keydown', Recaptcha.listener
$.bind $('#recaptcha_response_field', qr.el), 'keydown', qr.captchaKeydown $.bind $('#dummy', qr.el), 'keydown', qr.captchaKeydown
$.append d.body, qr.el $.append d.body, qr.el
@ -1116,9 +1114,6 @@ qr =
content = $('textarea', qr.el).value or $('input[type=file]', qr.el).files.length content = $('textarea', qr.el).value or $('input[type=file]', qr.el).files.length
return 'Error: No text entered.' unless content return 'Error: No text entered.' unless content
responseField = $ '#recaptcha_response_field', qr.el
return if responseField.value
### ###
captchas expire after 5 hours (couldn't find an official source, so captchas expire after 5 hours (couldn't find an official source, so
anonymous empirically verified). cutoff 5 minutes before then, b/c posting anonymous empirically verified). cutoff 5 minutes before then, b/c posting
@ -1132,12 +1127,12 @@ qr =
break break
$.set 'captchas', captchas $.set 'captchas', captchas
responseField.nextSibling.textContent = captchas.length + ' captchas' $('#captchas', qr.el).textContent = captchas.length + ' captchas'
return 'You forgot to type in the verification.' unless captcha return 'You forgot to type in the verification.' unless captcha
$('#recaptcha_challenge_field', qr.el).value = captcha.challenge $('#recaptcha_challenge_field', qr.el).value = captcha.challenge
responseField.value = captcha.response $('#recaptcha_response_field', qr.el).value = captcha.response
false false
@ -1177,7 +1172,7 @@ qr =
e.preventDefault() e.preventDefault()
alert msg alert msg
if msg is 'You forgot to type in the verification.' if msg is 'You forgot to type in the verification.'
$('#recaptcha_response_field', qr.el).focus() $('#dummy', qr.el).focus()
return return
if conf['Auto Watch Reply'] and conf['Thread Watcher'] if conf['Auto Watch Reply'] and conf['Thread Watcher']