From 5d2abe09b053c439aa9eaa9116529a36ed08dd15 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Wed, 16 May 2018 22:52:58 -0700 Subject: [PATCH] Allow the Quick Reply to be used on pages without an original post form such as archived threads. #242 --- src/Posting/Captcha.v2.coffee | 6 +++++- src/Posting/QR.coffee | 27 ++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Posting/Captcha.v2.coffee b/src/Posting/Captcha.v2.coffee index 32c2aa121..a0f2e0c98 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 if not (@isEnabled = !!$ '#g-recaptcha, #captcha-forced-noscript') + return if not (@isEnabled = !!$('#g-recaptcha, #captcha-forced-noscript') or !$.id('postForm')) if (@noscript = Conf['Force Noscript Captcha'] or not Main.jsEnabled) $.addClass QR.nodes.el, 'noscript-captcha' @@ -112,6 +112,10 @@ Captcha.v2 = window.onRecaptchaLoaded = -> render() cbNative() + unless document.head.querySelector 'script[src^="https://www.google.com/recaptcha/api.js"]' + script = document.createElement 'script' + script.src = 'https://www.google.com/recaptcha/api.js?onload=onRecaptchaLoaded&render=explicit' + document.head.appendChild script afterSetup: (mutations) -> for mutation in mutations diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 7d5b0de65..3bd19a0a7 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -26,8 +26,6 @@ QR = @posts = [] - return if g.VIEW is 'archive' - @captcha = Captcha.v2 $.on d, '4chanXInitFinished', -> BoardConfig.ready QR.initReady @@ -52,8 +50,7 @@ QR = Header.addShortcut 'qr', sc, 540 initReady: -> - QR.postingIsEnabled = !!$.id 'postForm' - return unless QR.postingIsEnabled + QR.postingIsEnabled = true {config} = g.BOARD prop = (key, def) -> +(config[key] ? def) @@ -72,14 +69,18 @@ QR = QR.forcedAnon = !!config.forced_anon QR.spoiler = !!config.spoilers - link = $.el 'h1', - className: "qr-link-container" - $.extend link, <%= html('?{g.VIEW === "thread"}{Reply to Thread}{Start a Thread}') %> + if (origToggle = $.id 'togglePostFormLink') + link = $.el 'h1', + className: "qr-link-container" + $.extend link, <%= html('?{g.VIEW === "thread"}{Reply to Thread}{Start a Thread}') %> - QR.link = link.firstElementChild - $.on link.firstChild, 'click', -> - QR.open() - QR.nodes.com.focus() + QR.link = link.firstElementChild + $.on link.firstChild, 'click', -> + QR.open() + QR.nodes.com.focus() + + $.before origToggle, link + origToggle.firstElementChild.textContent = 'Original Form' if g.VIEW is 'thread' linkBot = $.el 'div', @@ -92,10 +93,6 @@ QR = $.prepend navLinksBot, linkBot if (navLinksBot = $ '.navLinksBot') - origToggle = $.id 'togglePostFormLink' - $.before origToggle, link - origToggle.firstElementChild.textContent = 'Original Form' - $.on d, 'QRGetFile', QR.getFile $.on d, 'QRSetFile', QR.setFile