1

I'm making a Chrome extension and I want to manipulate the DOM on the Home, Popular, and Subreddit pages. When I open reddit, the image I am trying to display appears, but when I click on a link to a post, subreddit, or anywhere the image does not load on the next page. If I refresh the page, it appears (until I click onto another page).

My code is in a content script and I'm using JQuery. Here is the structure of my script.

$( "<div><img src='...'></div>" ).insertBefore( $(".CLASS") );

I'm not getting any error messages, but I wonder if it has to do with how reddit loads pages. How can I get it to manipulate the DOM for every page? Any advice would help.

  • Reddit loads the pages with ajax requests so that's why it only works when the page loads the first time. I would suggest trying to listen to any ajax response (.ajaxcomplete()) and then execute your code. – VVV Jul 06 '19 at 03:15
  • @VVV $( document ).ajaxComplete doesn't seem to work. What should I put in place of "$( document)" in my extension? – DirectCherry Jul 06 '19 at 03:30
  • See [this answer](https://stackoverflow.com/a/39508954) for the options. As for ajaxComplete you would have to [put it inside a **page script**](https://stackoverflow.com/a/9517879). – wOxxOm Jul 06 '19 at 04:05

0 Answers0