I am working on a Google Chrome extension and have something like the following code below. While there is nothing wrong with the code below there is a slight issue I am having trouble resolving.
I'm using this code to detect if the reports-content
class was changed from losing focus on an input control or if a timer was the action that caused the change.
The problem is, I only want to do something if the change was the result of losing focus on the input control and NOT the timer.
I want to do this so I can loop through different inputs and only try new inputs once the 'reports-content' has updated with new data.
The 'timer' is outside my control since it's on a third party website (tradingview.com), which happens to be using React framework in case that is important. Every-time the price changes it will detect as a mutation to the object I'm checking, which is not a bug, that is good that it does that, but I need to be able to discern which mutation was caused from that (timer/event/change), and which came from the input control losing focus.
Below is an example of the two mutation records I currently see, one caused by the event and the other the timer or (price change noticed event).
Below this is an example of what the reports-content looks like.
//When the DOM is ready set the mutation listner.
$(document).ready(function(){
console.log("JQuery Ready");
var observer = new MutationObserver(function(mutations) {
mutations.forEach(record => {
var recordTarget = record.target;
if(record.addedNodes.length>0){
if(recordTarget.classList.contains("reports-content")){
console.log(recordTarget);
console.log(record);
};
}
});
});
//Use mutation observer on 'body' to wait for the existence of the .reports-content class node
var target = $('body')[0];
var config = {
childList:true,
subtree: true
};
observer.observe(target, config);
});