Skip to content
Advertisement

How can I run a Greasemonkey script when page changed via ajax?

I have that script:

JavaScript

It works fine but it works only main page load. I want to run this when page changed via ajax. How can I do that?

Also please give examples with your answers. I’m newbie. I don’t know how to use things in your answers.

Advertisement

Answer

Since browser’s environment is event-driven you’ll have to either set up a timer, bind to some event that happens around update you looking for. Alternatively, you can wrap function that does update and call your code in post-hook. Obviously, you’ll need to wrap your userscript code in some function to reuse.

Here’s an example with timer set up with setInterval (top of script is still the same):

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement