From 7a11a5c70b8e78c24525205d9d0a7b97d13c0121 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Thu, 19 Nov 2015 12:46:54 -0800 Subject: [PATCH] Consolidate js-enabled tests. --- src/General/Main.coffee | 1 + src/Miscellaneous/Report.coffee | 4 ++-- src/Posting/Captcha.replace.coffee | 6 ++---- src/Posting/Captcha.v2.coffee | 2 +- src/Posting/QR.coffee | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/General/Main.coffee b/src/General/Main.coffee index a6b67c429..c1bd9a369 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -83,6 +83,7 @@ Main = $.global -> document.documentElement.classList.add 'js-enabled' window.FCX = {} + Main.jsEnabled = $.hasClass doc, 'js-enabled' switch hostname when 'www.4chan.org' diff --git a/src/Miscellaneous/Report.coffee b/src/Miscellaneous/Report.coffee index 5a9b64d4a..774f493a6 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 $.hasClass doc, 'js-enabled' + if Conf['Use Recaptcha v2 in Reports'] and Main.jsEnabled new MutationObserver(-> Report.fit 'iframe[src^="https://www.google.com/recaptcha/api2/frame"]' Report.fit 'body' @@ -38,7 +38,7 @@ Report = else Report.fit 'body' - if !Conf['Use Recaptcha v2 in Reports'] and $.hasClass(doc, 'js-enabled') and d.cookie.indexOf('pass_enabled=1') < 0 + if !Conf['Use Recaptcha v2 in Reports'] and Main.jsEnabled and d.cookie.indexOf('pass_enabled=1') < 0 $.onExists d.body, '#recaptcha_image', true, (image) -> # XXX Native reload-on-click breaks audio captcha. $.global -> document.getElementById('recaptcha_image').removeEventListener 'click', window.onAltCaptchaClick, false diff --git a/src/Posting/Captcha.replace.coffee b/src/Posting/Captcha.replace.coffee index 24d9d867c..6448a796e 100644 --- a/src/Posting/Captcha.replace.coffee +++ b/src/Posting/Captcha.replace.coffee @@ -3,13 +3,11 @@ 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'] - jsEnabled = $.hasClass doc, 'js-enabled' - - if location.hostname is 'sys.4chan.org' and Conf['Use Recaptcha v2 in Reports'] and jsEnabled + if location.hostname is 'sys.4chan.org' and Conf['Use Recaptcha v2 in Reports'] and Main.jsEnabled $.ready Captcha.replace.v2 return - if Conf['Use Recaptcha v1'] and jsEnabled and location.hostname isnt 'www.4chan.org' + if Conf['Use Recaptcha v1'] and Main.jsEnabled and location.hostname isnt 'www.4chan.org' $.ready Captcha.replace.v1 return diff --git a/src/Posting/Captcha.v2.coffee b/src/Posting/Captcha.v2.coffee index 9313f16af..5153d21b4 100644 --- a/src/Posting/Captcha.v2.coffee +++ b/src/Posting/Captcha.v2.coffee @@ -5,7 +5,7 @@ Captcha.v2 = return if d.cookie.indexOf('pass_enabled=1') >= 0 return unless @isEnabled = !!$ '#g-recaptcha, #captchaContainerAlt' - if @noscript = Conf['Force Noscript Captcha'] or not $.hasClass doc, 'js-enabled' + if @noscript = Conf['Force Noscript Captcha'] or not Main.jsEnabled @conn = new Connection null, "#{location.protocol}//www.google.com", token: (token) => @save true, token $.addClass QR.nodes.el, 'noscript-captcha' diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index f2a7ce495..3578641c0 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -56,7 +56,7 @@ QR = if Conf['Hide Original Post Form'] $.addClass doc, 'hide-original-post-form' - unless $.hasClass doc, 'js-enabled' + unless Main.jsEnabled # Prevent unnecessary loading of fallback iframe. $.onExists doc, '#postForm noscript', true, $.rm