0

Sites like YouTube and Facebook where as you scroll down more content is loaded. My JS injection works at first for content loaded at the beginner, but it no longer works on the new content. How do I solve this?

My JS:

$(".userContent:contains('the')").css("color", "green");

I tried the following but it didn't work:

chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
  if (changeInfo.status == 'complete') {

    // do your things
    $(".userContent:contains('the')").css("color", "green");
  }
})

What's the solution?

James Mitchell
  • 2,387
  • 4
  • 29
  • 59
  • 2
    See [Is there a JavaScript/jQuery DOM change listener?](//stackoverflow.com/a/39508954) – wOxxOm Feb 04 '17 at 20:09
  • The way to handle this is usually not by re-injecting your code. Your code is still there, but it is not listening for the changes to the DOM which are the way new content is loaded. For additional content which is fetched from a server, you could detect that data, and inform the content script, but the correct way is to detect the DOM changes. See the answer linked above. – Makyen Feb 05 '17 at 00:16
  • many other answered questions already answer this. – Zig Mandel Feb 06 '17 at 05:11
  • Possible duplicate of [Is there a JavaScript/jQuery DOM change listener?](http://stackoverflow.com/questions/2844565/is-there-a-javascript-jquery-dom-change-listener) – Makyen Feb 06 '17 at 23:07

0 Answers0