14

I have a GM script that adds buttons next to certain hyperlinks on Facebook pages. However, any AJAX update nukes the buttons in that section of page (i.e. when you click 'view more comments' - all the buttons on that thread vanish)

What I desire to do:
Re-run my GM function after certain AJAX operations complete - mainly when viewing more comments & loading a new page (I.e click to a different group page, this is all AJAXed)

what I currently do:
Have a 30 second loop that just re-runs my code every 30 seconds. not ideal. Setting a shorter loop will just cause lag
Edit - it actually makes more and more buttons. Super not ideal!

How you can help:
what code should I use to trigger my function after AJAX finishes loading something? What should I be doing so that my code only fires upon my desired AJAX updates, such as the 'new page' & 'more comments' updates?
Edit - I need to re-run my code only on the updated bit (is this even possible?)

Notes:
I have searched a bit and find a number answers for plain jQuery, asp.net, etc., but not the GM-jQ combo.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
RozzA
  • 609
  • 2
  • 9
  • 25

1 Answers1

14

This is a common problem.

Use the waitForKeyElements() function as shown in this answer.

By default, it will handle every new element, of the type that you specify via jQuery selector, once each, and within milliseconds of that new element appearing.

~~~
Link to the target page and specify exactly what you are doing for a more specific application.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • thank you good sir @brock - i will give this a whirl and see how i go. as for specifics i already explained at the top of my question. any facebook page & i am inserting a button next to certain hyperlinks (rallycries for DotD to be exact). – RozzA Apr 13 '12 at 03:52