ihavenoface/4chan-x — pull request #183 by Macil (2013-03-08 14:01:08+00:00)
Title: CAPTCHA checking before posting

This change makes it so when you cache a CAPTCHA with shift+enter, the CAPTCHA is validated before being cached. This solves the issue where you make a post, wait a while for it and maybe an image to upload, just to get told the CAPTCHA was bad and you have to do the upload again.

This behavior is optional and controlled by the new "Validate CAPTCHA" option, which defaults to on. If there are any connection errors in checking the CAPTCHA, then the CAPTCHA is cached anyway.

Uncached CAPTCHAs aren't checked, partly because it would be more difficult (the ajax check would have to happen in the submit handler, and queue the rest of the submission to happen later) and because if the connection to google's recaptcha server is slow for the user, the validation will slow down posting for the user.

It works by using the recaptcha's noscript fallback. If you don't have javascript turned on, then 4chan shows an iframe to a recaptcha page with a captcha, and when you solve it, it gives you a new challenge code to copy and paste into a field on the 4chan posting form. This allows the captcha validation to be decoupled from the actual posting.

Google's recaptcha server is a different domain from 4chan, so the ajax call to it is cross-domain, but it doesn't set its headers to explicitly allow that. Chrome allows userscripts to do cross-domain ajax calls by default. For Firefox Greasemonkey/Scriptish users, GM_xmlhttpRequest is used. I made a function $.crossAjax which acts as a wrapper for both of these. I haven't tested it in Opera.