From 244d40cd9315989d93b01d6df261af66b08fa209 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 22 Jun 2015 23:15:39 -0700 Subject: [PATCH] Implement replacement of captchas with v1 everywhere. --- src/General/Config.coffee | 9 ++++----- src/General/Main.coffee | 2 +- src/Posting/Captcha.noscript.coffee | 2 +- src/Posting/Captcha.replace.coffee | 19 ++++++++++++++++++- src/Posting/Captcha.v1.coffee | 2 +- src/Posting/Captcha.v2.coffee | 2 +- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 894a16d7e..14c9727ce 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -456,11 +456,6 @@ Config = 'Show notifications on successful post creation or file uploading.' 1 ] - 'Use Recaptcha v1': [ - false - 'Use the old text version of Recaptcha.' - 1 - ] 'Force Noscript Captcha': [ false 'Use the non-Javascript fallback captcha in the QR even if Javascript is enabled.' @@ -485,6 +480,10 @@ Config = true 'Make captcha easier to use, especially with the keyboard.' ] + 'Use Recaptcha v1': [ + false + 'Use the old text version of Recaptcha.' + ] 'Use Recaptcha v2 in Reports': [ false 'Use the image selection captcha in the report window.' diff --git a/src/General/Main.coffee b/src/General/Main.coffee index cc80cfe2c..793e98958 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -59,7 +59,7 @@ Main = $.onExists doc, 'body', false, Main.initStyle initFeatures: -> - if location.hostname in ['boards.4chan.org', 'sys.4chan.org'] + if location.hostname in ['boards.4chan.org', 'sys.4chan.org', 'www.4chan.org'] $.globalEval 'document.documentElement.classList.add("js-enabled");' switch location.hostname diff --git a/src/Posting/Captcha.noscript.coffee b/src/Posting/Captcha.noscript.coffee index 6edd8d378..70cef6409 100644 --- a/src/Posting/Captcha.noscript.coffee +++ b/src/Posting/Captcha.noscript.coffee @@ -3,7 +3,7 @@ Captcha.noscript = init: -> return if d.cookie.indexOf('pass_enabled=1') >= 0 - return unless @isEnabled = !!$.id 'g-recaptcha' + return unless @isEnabled = !!$ '#g-recaptcha, #captchaContainerAlt' container = $.el 'div', className: 'captcha-img' diff --git a/src/Posting/Captcha.replace.coffee b/src/Posting/Captcha.replace.coffee index 8a6f743fa..1a2b9f6ee 100644 --- a/src/Posting/Captcha.replace.coffee +++ b/src/Posting/Captcha.replace.coffee @@ -3,16 +3,33 @@ 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 location.hostname is 'sys.4chan.org' and Conf['Use Recaptcha v2 in Reports'] + jsEnabled = $.hasClass doc, 'js-enabled' + + if location.hostname is 'sys.4chan.org' and Conf['Use Recaptcha v2 in Reports'] and jsEnabled $.ready Captcha.replace.v2 return + if Conf['Use Recaptcha v1'] and jsEnabled + $.ready Captcha.replace.v1 + return + if Conf['captchaLanguage'].trim() if location.hostname is 'boards.4chan.org' $.onExists doc, '#captchaFormPart', true, (node) -> $.onExists node, 'iframe', true, Captcha.replace.iframe else $.onExists doc, 'iframe', true, Captcha.replace.iframe + v1: -> + return unless old = $.id 'g-recaptcha' + container = $.el 'div', + id: 'captchaContainerAlt' + $.replace old, container + Captcha.v1.setupScript() + if link = $ '#togglePostFormLink > a, #form-link' + $.on link, 'click', -> $.event 'captcha:setup', null, container + else + $.event 'captcha:setup', null, container + v2: -> return unless old = $.id 'captchaContainerAlt' container = $.el 'div', diff --git a/src/Posting/Captcha.v1.coffee b/src/Posting/Captcha.v1.coffee index 961a7bfab..afaa24e71 100644 --- a/src/Posting/Captcha.v1.coffee +++ b/src/Posting/Captcha.v1.coffee @@ -1,7 +1,7 @@ Captcha.v1 = init: -> return if d.cookie.indexOf('pass_enabled=1') >= 0 - return unless @isEnabled = !!$.id 'g-recaptcha' + return unless @isEnabled = !!$ '#g-recaptcha, #captchaContainerAlt' @setupScript() captchaContainer = $.el 'div', diff --git a/src/Posting/Captcha.v2.coffee b/src/Posting/Captcha.v2.coffee index 8d1674c98..ec5eb5989 100644 --- a/src/Posting/Captcha.v2.coffee +++ b/src/Posting/Captcha.v2.coffee @@ -3,7 +3,7 @@ Captcha.v2 = init: -> return if d.cookie.indexOf('pass_enabled=1') >= 0 - return unless @isEnabled = !!$.id 'g-recaptcha' + return unless @isEnabled = !!$ '#g-recaptcha, #captchaContainerAlt' if @noscript = Conf['Force Noscript Captcha'] or not $.hasClass doc, 'js-enabled' @conn = new Connection null, "#{location.protocol}//www.google.com",