Work around captcha bug causing captcha to go offscreen to the right. #550

This commit is contained in:
ccd0 2015-10-30 09:26:01 -07:00
parent 4f423b5f7c
commit 1895d5e589

View File

@ -34,6 +34,8 @@ Captcha.v2 =
$.on window, 'captcha:success', =>
# XXX Greasemonkey 1.x workaround to gain access to GM_* functions.
$.queueTask => @save false
new MutationObserver(@watchBubbles.bind @).observe d.body,
childList: true
initFrame: ->
if token = $('.fbc-verification-token > textarea')?.value
@ -228,3 +230,20 @@ Captcha.v2 =
window.grecaptcha.reset(container.dataset.widgetID);
})();
'''
watchBubbles: (mutations) ->
for mutation in mutations
for node in mutation.addedNodes
if $ 'iframe[src^="https://www.google.com/recaptcha/api2/frame"]', node
new MutationObserver(@fixBubble.bind(@, node)).observe node,
attributes: true
fixBubble: (node) ->
{bottom, right, width} = node.getBoundingClientRect()
if (
bottom > 0 and # not deliberately offscreen
right > doc.clientWidth # offscreen to right
)
qrLeft = QR.nodes.el.getBoundingClientRect().left
newLeft = Math.max 0, qrLeft - width
node.style.left = "#{newLeft}px"