MCPcopy
hub / github.com/mailvelope/mailvelope / on

Function on

src/content-scripts/main.js:110–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

108}
109
110function 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
138function off() {
139 if (domObserver) {

Callers 1

initFunction · 0.70

Calls 3

scanDOMFunction · 0.85
observeMethod · 0.80
updateElementsMethod · 0.80

Tested by

no test coverage detected