0

I am writing a GreaseMonkey script that needs to change HTML code in the page. The page is modifying himself after AJAX request. How can i run code when page modified? Is there any event of adding / modifying element in page?

thank you.

user2153436
  • 81
  • 1
  • 1
  • 7
  • Ajax has a call back method, you can do what ever you want in that method. Paste your code here so we can see and suggest you – Umair Hamid Mar 07 '15 at 08:34
  • I am not calling the Ajax request. The page does it. I am writing an Userscript for this page. Is there any event that running when an element added \ changed ? – user2153436 Mar 07 '15 at 08:38
  • Hoe the page does it? – Umair Hamid Mar 07 '15 at 08:39
  • there is a function called `ajaxHandlerCall` that sending an Ajax request and modifying the page. – user2153436 Mar 07 '15 at 08:46
  • Please read its documentation, you may get a call back method which you can use after ajax complete. – Umair Hamid Mar 07 '15 at 08:48
  • I am not calling the `ajaxHandlerCall` function. The page himself does it, so i can't provide callback method. – user2153436 Mar 07 '15 at 08:56
  • One idea could be just use `setInterval` to check every few seconds, if the change in the HTML has happend. – RoToRa Mar 07 '15 at 11:10
  • @RoToRa it's not so elegant way. Is there any way to set callback function for DOM element change? – user2153436 Mar 09 '15 at 14:24
  • is [`MutationObserver`](https://developer.mozilla.org/docs/Web/API/MutationObserver) what you need? You may also modify the `ajaxHandlerCall` via `unsafeWindow`, but pay attention to sandbox issues. – tsh Mar 10 '15 at 08:56
  • 1
    You can use Brock's waitForKeyElements function (https://gist.github.com/BrockA/2625891) – Edge Apr 05 '15 at 01:29

0 Answers0