From 86efc2da80085833f7d7b10df156b549abea2af6 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Tue, 10 Oct 2023 17:17:47 -0400 Subject: [PATCH] use MutationObserver to track dom node additions. --- src/gmail.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/gmail.js b/src/gmail.js index 44a56a7..d15fe69 100644 --- a/src/gmail.js +++ b/src/gmail.js @@ -2672,13 +2672,6 @@ var Gmail = function(localJQuery) { api.tracker.observing_dom = true; //api.tracker.dom_watchdog = {}; // store passed observer callbacks for different DOM events - // this listener will check every element inserted into the DOM - // for specified classes (as defined in api.tracker.dom_observers above) which indicate - // related actions which need triggering - $(window.document).on("DOMNodeInserted", function(e) { - api.tools.insertion_observer(e.target, api.tracker.dom_observers, api.tracker.dom_observer_map); - }); - // recipient_change also needs to listen to removals var mutationObserver = new MutationObserver(function(mutations) { for (var i = 0; i < mutations.length; i++) { @@ -2697,6 +2690,15 @@ var Gmail = function(localJQuery) { api.observe.trigger_dom(observer, $(mutation.target), handler); } } + + // this listener will check every element inserted into the DOM + // for specified classes (as defined in api.tracker.dom_observers above) which indicate + // related actions which need triggering + var addedNodes = mutation.addedNodes; + for (var k = 0; k < addedNodes.length; k++) { + var addedNode = addedNodes[k]; + api.tools.insertion_observer(addedNode, api.tracker.dom_observers, api.tracker.dom_observer_map); + } } }); mutationObserver.observe(document.body, {subtree: true, childList: true});