diff --git a/src/Posting/QR.captcha.coffee b/src/Posting/QR.captcha.coffee index e098ecc74..f21b9a0a7 100644 --- a/src/Posting/QR.captcha.coffee +++ b/src/Posting/QR.captcha.coffee @@ -10,20 +10,15 @@ QR.captcha = section = $.el 'div', className: 'captcha-section' $.extend section, <%= html( - '
' + '' ) %> container = $ '.captcha-container', section counter = $ '.captcha-counter > a', section - @nodes = {container, counter} + @nodes = {section, container, counter} @count() $.addClass QR.nodes.el, 'has-captcha' $.after QR.nodes.com.parentNode, section - new MutationObserver(@afterSetup.bind @).observe container, - childList: true - subtree: true - $.on counter, 'click', @toggle.bind @ $.on window, 'captcha:success', @save.bind @ @@ -32,13 +27,13 @@ QR.captcha = needed: -> captchaCount = @captchas.length - captchaCount++ if @nodes.container.dataset.widgetID and !@timeouts.destroy + captchaCount++ if @nodes.container and !@timeouts.destroy postsCount = QR.posts.length postsCount = 0 if postsCount is 1 and !Conf['Auto-load captcha'] and !QR.posts[0].com and !QR.posts[0].file captchaCount < postsCount toggle: -> - if @nodes.container.dataset.widgetID and !@timeouts.destroy + if @nodes.container and !@timeouts.destroy @destroy() else @shouldFocus = true @@ -51,7 +46,15 @@ QR.captcha = clearTimeout @timeouts.destroy delete @timeouts.destroy return @reload() - return if @nodes.container.dataset.widgetID + + return if @nodes.container + + @nodes.container = $.el 'div', className: 'captcha-container' + $.prepend @nodes.section, @nodes.container + new MutationObserver(@afterSetup.bind @).observe @nodes.container, + childList: true + subtree: true + $.globalEval ''' (function() { var container = document.querySelector("#qr .captcha-container"); @@ -80,9 +83,8 @@ QR.captcha = return unless @isEnabled delete @timeouts.destroy $.rmClass QR.nodes.el, 'captcha-open' - $.rmAll @nodes.container - # XXX https://github.com/greasemonkey/greasemonkey/issues/1571 - @nodes.container.removeAttribute 'data-widget-i-d' + $.rm @nodes.container + delete @nodes.container sync: (captchas) -> @captchas = captchas