Consolidate js-enabled tests.

This commit is contained in:
ccd0 2015-11-19 12:46:54 -08:00
parent 6dc10d2c1f
commit 7a11a5c70b
5 changed files with 7 additions and 8 deletions

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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