From 210b6bd20161286ace683ad1590a8df637f60de7 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Thu, 19 Nov 2015 16:39:33 -0800 Subject: [PATCH] Make 'Force Noscript Captcha' work on all forms. #262 --- src/General/Config.coffee | 9 ++++----- src/Miscellaneous/Report.coffee | 2 +- src/Posting/Captcha.replace.coffee | 12 ++++++++++++ src/Posting/QR.coffee | 5 ++++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 646dc813b..0d90af310 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -470,11 +470,6 @@ Config = 'Show notifications on successful post creation or file uploading.' 1 ] - 'Force Noscript Captcha': [ - false - 'Use the non-Javascript fallback captcha in the QR even if Javascript is enabled (Recaptcha v2 only).' - 1 - ] 'Auto-load captcha': [ false 'Automatically load the captcha in the QR even if your post is empty.' @@ -502,6 +497,10 @@ Config = false 'Use the image selection captcha in the report window.' ] + 'Force Noscript Captcha': [ + false + 'Use the non-Javascript fallback captcha even if Javascript is enabled (Recaptcha v2 only).' + ] 'Pass Link': [ true 'Add a 4chan Pass login link to the bottom of the page.' diff --git a/src/Miscellaneous/Report.coffee b/src/Miscellaneous/Report.coffee index 774f493a6..49934947a 100644 --- a/src/Miscellaneous/Report.coffee +++ b/src/Miscellaneous/Report.coffee @@ -27,7 +27,7 @@ Report = target: '_blank' ] - if Conf['Use Recaptcha v2 in Reports'] and Main.jsEnabled + if Conf['Use Recaptcha v2 in Reports'] and not Conf['Force Noscript Captcha'] and Main.jsEnabled new MutationObserver(-> Report.fit 'iframe[src^="https://www.google.com/recaptcha/api2/frame"]' Report.fit 'body' diff --git a/src/Posting/Captcha.replace.coffee b/src/Posting/Captcha.replace.coffee index 6448a796e..d3e46d1d9 100644 --- a/src/Posting/Captcha.replace.coffee +++ b/src/Posting/Captcha.replace.coffee @@ -3,6 +3,10 @@ Captcha.replace = return unless d.cookie.indexOf('pass_enabled=1') < 0 return if location.hostname is 'boards.4chan.org' and Conf['Hide Original Post Form'] + if Conf['Force Noscript Captcha'] and Main.jsEnabled + $.ready Captcha.replace.noscript + return + if location.hostname is 'sys.4chan.org' and Conf['Use Recaptcha v2 in Reports'] and Main.jsEnabled $.ready Captcha.replace.v2 return @@ -17,6 +21,14 @@ Captcha.replace = else $.onExists doc, 'iframe', true, Captcha.replace.iframe + noscript: -> + return unless (original = $ '#g-recaptcha, #captchaContainerAlt') and (noscript = $ 'noscript') + span = $.el 'span', + innerHTML: noscript.textContent + Captcha.replace.iframe $('iframe', span) + $.replace noscript, span + original.hidden = true + v1: -> return unless $.id 'g-recaptcha' Captcha.v1.replace() diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 3578641c0..cef65ef6d 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -29,7 +29,10 @@ QR = return if g.VIEW is 'archive' - version = if Conf['Use Recaptcha v1'] then 'v1' else 'v2' + version = if Conf['Use Recaptcha v1'] and not Conf['Force Noscript Captcha'] and Main.jsEnabled + 'v1' + else + 'v2' @captcha = Captcha[version] $.on d, '4chanXInitFinished', @initReady