I'm trying to write my first, very simple Google Chrome extension as a joke for a friend. I want it to replace instances of "like" with "give a $h1t" (I know this doesn't seem mature, but it's just for fun).
This is my Javascript function so far;
function giveASh!t(){
document.body.innerHTML = document.body.innerHTML.replace(new RegExp("Like", "g"), "Give a sh!t");
}
As I understand it, that searches through the HTML replacing every instance of "Like" with my alternative. This works.
However, the issue I'm facing is when you scroll down through your news feed, newly generated content does not get altered, any new instances of "Like" are not modified.
I understand that this code is executed once the initial page has finished loading, and once it's executed it is not re-run.
I've played about with the setInterval() method, and that lead to some strange errors. I set it to an interval of 10 seconds, but it would affect the loading of other content on the page (such as the chat section), and also was not too nice as the page would 'stutter' as if undergoing a refresh. Eventually the page would break, and it was impossible to scroll down the newsfeed any further.
My main point is; how can I get this javascript to run continuously, in a nice way? Perhaps a better way would be to listen for scroll events, and then run the javascript?