Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use MutationObserver to track dom node additions. #767

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/gmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@
"false": !1,
"null": null
};
each(params.replace(/\+/g, " ").split("&"), function (v, j) {

Check warning on line 742 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'j' is defined but never used

Check warning on line 742 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (17.x)

'j' is defined but never used

Check warning on line 742 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'j' is defined but never used
var param = v.split("="),
key = decodeURIComponent(param[0]),
val,
Expand Down Expand Up @@ -790,7 +790,7 @@
}
};

api.tools.parse_actions = function(params, xhr) {

Check warning on line 793 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'xhr' is defined but never used

Check warning on line 793 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (17.x)

'xhr' is defined but never used

Check warning on line 793 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'xhr' is defined but never used

// upload_attachment event - if found, don"t check other observers. See issue #22
if(params.url.act === "fup" || params.url.act === "fuv" || params.body_is_object) {
Expand Down Expand Up @@ -1908,7 +1908,7 @@
}

let parsedResponse = [];
let originalResponse = response;

Check warning on line 1911 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'originalResponse' is assigned a value but never used

Check warning on line 1911 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (17.x)

'originalResponse' is assigned a value but never used

Check warning on line 1911 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'originalResponse' is assigned a value but never used
try {
// gmail post response structure
// )}]"\n<datalength><rawData>\n<dataLength><rawData>...
Expand Down Expand Up @@ -2087,7 +2087,7 @@
const win = api.helper.get_xhr_window();

api.tools.patch(win.XMLHttpRequest.prototype.open, (orig) => {
win.XMLHttpRequest.prototype.open = function (method, url, async, user, password) {

Check warning on line 2090 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'async' is defined but never used

Check warning on line 2090 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'user' is defined but never used

Check warning on line 2090 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'password' is defined but never used

Check warning on line 2090 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (17.x)

'async' is defined but never used

Check warning on line 2090 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (17.x)

'user' is defined but never used

Check warning on line 2090 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (17.x)

'password' is defined but never used

Check warning on line 2090 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'async' is defined but never used

Check warning on line 2090 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'user' is defined but never used

Check warning on line 2090 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'password' is defined but never used
var out = orig.apply(this, arguments);
this.xhrParams = {
method: method.toString(),
Expand Down Expand Up @@ -2353,7 +2353,7 @@
// if an object of actions (triggered events of format { event: [response] }) is passed, check if any of these are bound
if(typeof action === "object") {
var match = false;
$.each(action,function(key,response){

Check warning on line 2356 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'response' is defined but never used

Check warning on line 2356 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (17.x)

'response' is defined but never used

Check warning on line 2356 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'response' is defined but never used
if(typeof api.tracker.watchdog[type][key] === "object") match = true;
});
return match;
Expand Down Expand Up @@ -2389,7 +2389,7 @@
delete api.tracker.watchdog[type][action];
}
} else {
$.each(api.tracker.watchdog[type], function(act,callbacks) {

Check warning on line 2392 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'callbacks' is defined but never used

Check warning on line 2392 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (17.x)

'callbacks' is defined but never used

Check warning on line 2392 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'callbacks' is defined but never used
if(typeof api.tracker.watchdog[type][act] === "object") {
api.tracker.bound[act] -= api.tracker.watchdog[type][act].length;
api.tracker.bound[type] -= api.tracker.watchdog[type][act].length;
Expand Down Expand Up @@ -2672,13 +2672,6 @@
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++) {
Expand All @@ -2697,6 +2690,15 @@
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});
Expand Down Expand Up @@ -2744,7 +2746,7 @@

// observes every element inserted into the DOM by Gmail and looks at the classes on those elements,
// checking for any configured observers related to those classes
api.tools.insertion_observer = function(target, dom_observers, dom_observer_map, sub) {

Check warning on line 2749 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'sub' is defined but never used

Check warning on line 2749 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (17.x)

'sub' is defined but never used

Check warning on line 2749 in src/gmail.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'sub' is defined but never used
//console.log("insertion", target, target.className);
if(!dom_observer_map) return;

Expand Down
Loading