adeekshith / Docs-Online-Viewer

Open publicly available online files directly in the browser using free online services without need for downloading or using third party plugins.
http://dov.parishod.com/
24 stars 4 forks source link

Use of Mutation Events is deprecated. Use MutationObserver instead. #9

Open adeekshith opened 8 years ago

adeekshith commented 8 years ago

JS console in Firefox reports that Use of Mutation Events is deprecated. Use MutationObserver instead. at 127774.user.js#L144

Code:

    document.addEventListener('DOMNodeInserted',function(e)
    { ...
adeekshith commented 8 years ago

This is occurring in setupListener() function in 127774.js. I have no idea what it is doing and why it is needed. Code seems to work well even without this. Need testing and remove it if not needed. Here is the code involved in this issue:

function setupListener()
{
    document.addEventListener('DOMNodeInserted',function(e)
    {
        if (doCheck)
        {
            doCheck = false;
            setTimeout(function(){checkLinks();doCheck = true;}, 1000);
        } 
  },false);
}
adeekshith commented 8 years ago

Got it! It checks for all links every time a new node is inserted into DOM. It should be done using MutationObservers as MutationEvents are deprecated long time ago. Also modify it to check only the new nodes if possible instead of all the links every time a new node is inserted if possible. References:

  1. Detect DOM changes with MutationObservers
  2. Detect, Undo And Redo DOM Changes With Mutation Observers