1

I am pretty new in this area. I haven't coded much in JavaScript and have only basic knowledge when it comes to build a chrome extension.

I have built a chrome extension that marks YouTube videos according to their category.

For example, if the user selects to search videos related to Education category, the extension would mark them with different background.

The code works great but my problem is when the user scrolls down (to see more videos), the new videos aren't marked (because my script run only when page loads).

Is there a way to listen to this loading event so I can run my function again?

I am using YouTube Data API V3 to get the category of the video.

Thanks in advance

SagiZiv
  • 932
  • 1
  • 16
  • 38
  • Use MutationObserver or interval polling, see [Is there a JavaScript / jQuery DOM change listener?](https://stackoverflow.com/a/39508954) – wOxxOm May 30 '20 at 12:12
  • @wOxxOm Thanks for the response, the link really helped me learn more about the extension. But, unfortunately, I am still unable to detect when new videos are added. One thing I can do is to listen to the scroll event and check if the number of elements has changed, but it isn't that performant... – SagiZiv May 30 '20 at 14:51
  • It means you've used MutationObserver incorrectly. As for performance concerns you need to actually measure it in devtools instead of guessing. There should be no problem in listening to scroll event and checking the amount of elements however it's less reliable than MutationObserver. – wOxxOm May 30 '20 at 15:53

0 Answers0