OLD | NEW |
(Empty) | |
| 1 (function() { |
| 2 |
| 3 function click(button) { |
| 4 var rect = button.getBoundingClientRect(); |
| 5 eventSender.mouseMoveTo(rect.left, rect.top); |
| 6 eventSender.mouseDown(); |
| 7 eventSender.mouseUp(); |
| 8 } |
| 9 |
| 10 var observer = new MutationObserver(mutations => { |
| 11 for (var mutation of mutations) { |
| 12 for (var node of mutation.addedNodes) { |
| 13 if (node.localName == 'button') |
| 14 click(node); |
| 15 else if (node.localName == 'iframe') |
| 16 observe(node.contentDocument); |
| 17 } |
| 18 } |
| 19 }); |
| 20 |
| 21 function observe(target) { |
| 22 observer.observe(target, { childList: true, subtree: true }); |
| 23 } |
| 24 |
| 25 // Handle what's already in the document. |
| 26 for (var button of document.getElementsByTagName('button')) { |
| 27 click(button); |
| 28 } |
| 29 for (var iframe of document.getElementsByTagName('iframe')) { |
| 30 observe(iframe.contentDocument); |
| 31 } |
| 32 |
| 33 // Observe future changes. |
| 34 observe(document); |
| 35 |
| 36 })(); |
OLD | NEW |