()
| 108 | } |
| 109 | |
| 110 | function on() { |
| 111 | if (clientApiActive) { |
| 112 | return; // do not use DOM scan in case of clientAPI support |
| 113 | } |
| 114 | const mutateEvent = new CustomEvent('mailvelope-observe'); |
| 115 | // let hasMutated = false; |
| 116 | let timeout = null; |
| 117 | const next = () => { |
| 118 | scanDOM(); |
| 119 | document.dispatchEvent(mutateEvent); |
| 120 | }; |
| 121 | domObserver = new MutationObserver(() => { |
| 122 | clearTimeout(timeout); |
| 123 | timeout = setTimeout(next, OBSERVER_TIMEOUT); |
| 124 | }); |
| 125 | clickHandler = () => { |
| 126 | clearTimeout(timeout); |
| 127 | timeout = setTimeout(next, OBSERVER_TIMEOUT); |
| 128 | }; |
| 129 | document.addEventListener('click', clickHandler, {capture: true}); |
| 130 | domObserver.observe(document.body, {subtree: true, childList: true}); |
| 131 | // start DOM scan |
| 132 | scanDOM(); |
| 133 | if (currentProvider?.integration) { |
| 134 | currentProvider.integration.updateElements(); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | function off() { |
| 139 | if (domObserver) { |
no test coverage detected