Greasemonkey wait for delayed loaded content

5,457 views
Skip to first unread message

Ganesh Ranganathan

unread,
Jul 28, 2010, 12:53:56 AM7/28/10
to greasemonkey-users
Hi, In one of the sites I am trying to modify, the main content is
loaded through AJAX after the page has loaded. So my GM script is
firing before the content is loaded.

I tried to make it wait using setTimeout but it still doesnt seem to
work. Any ideas?

Thanks and Regards,
Ganesh Ranganathan

Vectorspace

unread,
Jul 28, 2010, 1:28:10 AM7/28/10
to greasemon...@googlegroups.com
Pick an element of the main content that, if it exists, indicates to
you that the page has finished loading.

Use document.getElementByID, or ByName, or ByTagName, or some other
method to check for the existence of this element - if it does not exist
use setTimeout to wait for a second or so before retrying, and keep
retrying until it exists.
If/when it does exist, execute the rest of your script.

Erik Vold

unread,
Jul 28, 2010, 1:34:52 AM7/28/10
to greasemon...@googlegroups.com
Use one of the events listed here: https://developer.mozilla.org/en/DOM_Events

I'd suggest using DOMSubtreeModified or DOMNodeInserted on an element which is changed after the AJAX content is loaded, this way your code is executed at the correct moment in time.

E

--
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemon...@googlegroups.com.
To unsubscribe from this group, send email to greasemonkey-us...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en.


Ganesh Ranganathan

unread,
Jul 28, 2010, 12:19:54 PM7/28/10
to greasemonkey-users
Thanks Erik and Vectorspace, I got it working now. But ran into
another problem with content that is delayed loaded.

I am using JQuery and binding the DOMNodeInserted event. In the event
handler I am trying to unbind it so it doesnt fire multiple times for
each inserted node. Yet the browser gets stuck in a recursion loop and
I have to end task it.

Any idea how to unbind the DOMNodeInserted event handler so it fires
just once.

On Jul 28, 10:34 am, Erik Vold <erikvv...@gmail.com> wrote:
> Use one of the events listed here:https://developer.mozilla.org/en/DOM_Events
>
> I'd suggest using DOMSubtreeModified or DOMNodeInserted on an element which
> is changed after the AJAX content is loaded, this way your code is executed
> at the correct moment in time.
>
> E
>
> Erik Vergobbi Vold
>
> Email: erikvv...@gmail.com
> Website:http://erikvold.com/
> Twitter:http://twitter.com/erikvold
> Identi.ca:http://identi.ca/erikvold
> LinkedIn:http://www.linkedin.com/in/erikvold
>
> On Tue, Jul 27, 2010 at 21:53, Ganesh Ranganathan <
>
> ganesh.ranganathan...@gmail.com> wrote:
> > Hi, In one of the sites I am trying to modify, the main content is
> > loaded through AJAX after the page has loaded. So my GM script is
> > firing before the content is loaded.
>
> > I tried to make it wait using setTimeout but it still doesnt seem to
> > work. Any ideas?
>
> > Thanks and Regards,
> > Ganesh Ranganathan
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "greasemonkey-users" group.
> > To post to this group, send email to greasemon...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > greasemonkey-us...@googlegroups.com<greasemonkey-users%2Bunsu...@googlegroups.com>
> > .

Jonas Colbro

unread,
Jan 22, 2014, 7:49:32 AM1/22/14
to greasemon...@googlegroups.com
Sounds like exactly what i need could you give an example code for this. 

I have an element with a specific classname i need to fins before everyting is reday.
Reply all
Reply to author
Forward
0 new messages