Use a new container for new captchas.
This commit is contained in:
parent
6fb037eb9e
commit
177878f660
@ -10,20 +10,15 @@ QR.captcha =
|
|||||||
|
|
||||||
section = $.el 'div', className: 'captcha-section'
|
section = $.el 'div', className: 'captcha-section'
|
||||||
$.extend section, <%= html(
|
$.extend section, <%= html(
|
||||||
'<div class="captcha-container"></div>' +
|
|
||||||
'<div class="captcha-counter"><a href="javascript:;"></a></div>'
|
'<div class="captcha-counter"><a href="javascript:;"></a></div>'
|
||||||
) %>
|
) %>
|
||||||
container = $ '.captcha-container', section
|
container = $ '.captcha-container', section
|
||||||
counter = $ '.captcha-counter > a', section
|
counter = $ '.captcha-counter > a', section
|
||||||
@nodes = {container, counter}
|
@nodes = {section, container, counter}
|
||||||
@count()
|
@count()
|
||||||
$.addClass QR.nodes.el, 'has-captcha'
|
$.addClass QR.nodes.el, 'has-captcha'
|
||||||
$.after QR.nodes.com.parentNode, section
|
$.after QR.nodes.com.parentNode, section
|
||||||
|
|
||||||
new MutationObserver(@afterSetup.bind @).observe container,
|
|
||||||
childList: true
|
|
||||||
subtree: true
|
|
||||||
|
|
||||||
$.on counter, 'click', @toggle.bind @
|
$.on counter, 'click', @toggle.bind @
|
||||||
$.on window, 'captcha:success', @save.bind @
|
$.on window, 'captcha:success', @save.bind @
|
||||||
|
|
||||||
@ -32,13 +27,13 @@ QR.captcha =
|
|||||||
|
|
||||||
needed: ->
|
needed: ->
|
||||||
captchaCount = @captchas.length
|
captchaCount = @captchas.length
|
||||||
captchaCount++ if @nodes.container.dataset.widgetID and !@timeouts.destroy
|
captchaCount++ if @nodes.container and !@timeouts.destroy
|
||||||
postsCount = QR.posts.length
|
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
|
postsCount = 0 if postsCount is 1 and !Conf['Auto-load captcha'] and !QR.posts[0].com and !QR.posts[0].file
|
||||||
captchaCount < postsCount
|
captchaCount < postsCount
|
||||||
|
|
||||||
toggle: ->
|
toggle: ->
|
||||||
if @nodes.container.dataset.widgetID and !@timeouts.destroy
|
if @nodes.container and !@timeouts.destroy
|
||||||
@destroy()
|
@destroy()
|
||||||
else
|
else
|
||||||
@shouldFocus = true
|
@shouldFocus = true
|
||||||
@ -51,7 +46,15 @@ QR.captcha =
|
|||||||
clearTimeout @timeouts.destroy
|
clearTimeout @timeouts.destroy
|
||||||
delete @timeouts.destroy
|
delete @timeouts.destroy
|
||||||
return @reload()
|
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 '''
|
$.globalEval '''
|
||||||
(function() {
|
(function() {
|
||||||
var container = document.querySelector("#qr .captcha-container");
|
var container = document.querySelector("#qr .captcha-container");
|
||||||
@ -80,9 +83,8 @@ QR.captcha =
|
|||||||
return unless @isEnabled
|
return unless @isEnabled
|
||||||
delete @timeouts.destroy
|
delete @timeouts.destroy
|
||||||
$.rmClass QR.nodes.el, 'captcha-open'
|
$.rmClass QR.nodes.el, 'captcha-open'
|
||||||
$.rmAll @nodes.container
|
$.rm @nodes.container
|
||||||
# XXX https://github.com/greasemonkey/greasemonkey/issues/1571
|
delete @nodes.container
|
||||||
@nodes.container.removeAttribute 'data-widget-i-d'
|
|
||||||
|
|
||||||
sync: (captchas) ->
|
sync: (captchas) ->
|
||||||
@captchas = captchas
|
@captchas = captchas
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user