From e8276ca800a87eda250de17480a1f31053f42929 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 30 Jan 2016 00:24:59 -0800 Subject: [PATCH] Use the &altc=1 report form but substitute our own captcha options. Also - fix tab order in report form - focus on captcha in report form - extend refresh on image click / backspace to original post form - support language setting for v1 (#458) --- src/Menu/ReportLink.coffee | 7 ++++--- src/Miscellaneous/Report.coffee | 10 ---------- src/Posting/Captcha.replace.coffee | 6 ++++++ src/Posting/Captcha.v1.coffee | 25 ++++++++++++++++++++++--- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/Menu/ReportLink.coffee b/src/Menu/ReportLink.coffee index 8b7ad99cf..cb666a535 100644 --- a/src/Menu/ReportLink.coffee +++ b/src/Menu/ReportLink.coffee @@ -14,10 +14,11 @@ ReportLink = unless post.isDead or (post.thread.isDead and not post.thread.isArchived) a.textContent = 'Report' ReportLink.url = "//sys.4chan.org/#{post.board}/imgboard.php?mode=report&no=#{post}" - ReportLink.dims = if Conf['Use Recaptcha v1 in Reports'] or d.cookie.indexOf('pass_enabled=1') >= 0 - 'width=350,height=275' + if (Conf['Use Recaptcha v1 in Reports'] and Main.jsEnabled) or d.cookie.indexOf('pass_enabled=1') >= 0 + ReportLink.url += '&altc=1' + ReportLink.dims = 'width=350,height=275' else - 'width=400,height=550' + ReportLink.dims = 'width=400,height=550' else if Conf['Archive Report'] a.textContent = 'Report to archive' ReportLink.url = Redirect.to 'report', {boardID: post.board.ID, postID: post.ID} diff --git a/src/Miscellaneous/Report.coffee b/src/Miscellaneous/Report.coffee index ab9333073..ea2e19086 100644 --- a/src/Miscellaneous/Report.coffee +++ b/src/Miscellaneous/Report.coffee @@ -38,16 +38,6 @@ Report = else Report.fit 'body' - if Conf['Use Recaptcha v1 in Reports'] and Main.jsEnabled and d.cookie.indexOf('pass_enabled=1') < 0 - $.onExists d.body, '#recaptcha_image', (image) -> - $.on image, 'click', -> - if $.id 'recaptcha_challenge_image' - $.global -> window.Recaptcha.reload() - $.onExists d.body, '#recaptcha_response_field', (field) -> - $.on field, 'keydown', (e) -> - if e.keyCode is 8 and not field.value - $.global -> window.Recaptcha.reload() - fit: (selector) -> return unless (el = $ selector, doc) and getComputedStyle(el).visibility isnt 'hidden' dy = el.getBoundingClientRect().bottom - doc.clientHeight + 8 diff --git a/src/Posting/Captcha.replace.coffee b/src/Posting/Captcha.replace.coffee index fbbd0cc46..db691b7b4 100644 --- a/src/Posting/Captcha.replace.coffee +++ b/src/Posting/Captcha.replace.coffee @@ -2,6 +2,12 @@ Captcha.replace = init: -> return unless d.cookie.indexOf('pass_enabled=1') < 0 + if location.hostname is 'sys.4chan.org' and /[?&]altc\b/.test(location.search) and Main.jsEnabled + $.onExists doc, 'script[src="//www.google.com/recaptcha/api/js/recaptcha_ajax.js"]', -> + $.global -> window.el.onload = null + Captcha.v1.create() + return + if ( (Conf['Use Recaptcha v1'] and location.hostname is 'boards.4chan.org') or (Conf['Use Recaptcha v1 in Reports'] and location.hostname is 'sys.4chan.org') diff --git a/src/Posting/Captcha.v1.coffee b/src/Posting/Captcha.v1.coffee index b0eacdc05..577ebd031 100644 --- a/src/Posting/Captcha.v1.coffee +++ b/src/Posting/Captcha.v1.coffee @@ -50,12 +50,30 @@ Captcha.v1 = $.replace old, container create: -> + cont = $.id 'captchaContainerAlt' + return if @occupied + + @occupied = true + + if (lang = Conf['captchaLanguage'].trim()) + cont.dataset.lang = lang + + $.onExists cont, '#recaptcha_image', (image) -> + $.on image, 'click', -> + if $.id 'recaptcha_challenge_image' + $.global -> window.Recaptcha.reload() + $.onExists cont, '#recaptcha_response_field', (field) -> + $.on field, 'keydown', (e) -> + if e.keyCode is 8 and not field.value + $.global -> window.Recaptcha.reload() + field.focus() if location.hostname is 'sys.4chan.org' + $.global -> container = document.getElementById 'captchaContainerAlt' - return if container.firstChild options = - theme: 'clean' - tabindex: {"boards.4chan.org": 5, "sys.4chan.org": 3}[location.hostname] + theme: 'clean' + tabindex: {"boards.4chan.org": 5}[location.hostname] + lang: container.dataset.lang if window.Recaptcha window.Recaptcha.create '<%= meta.recaptchaKey %>', container, options else @@ -123,6 +141,7 @@ Captcha.v1 = destroy: -> return unless @script $.global -> window.Recaptcha.destroy() + delete @occupied @beforeSetup() if @nodes sync: (captchas=[]) ->