execute greasymonkey only once per website

353 views
Skip to first unread message

Nico Gerwien

unread,
May 14, 2011, 9:53:50 AM5/14/11
to greasemonkey-users
Hi,

i wrote a small HelloWorld Script with Greasymonkey and did something
like this:
...
alert(jQuery);
alert(jQuery().jquery);

So the problem is Greasemonkey executes my userscript on some sites
more than once. In this case i get the alert messages many times.

I would like to know if there is a way to ensure that a userscript is
only executed once per website. Or maybe prevent the script to execute
on embedded sites.

Greetz.

Matt Sargent

unread,
May 14, 2011, 10:12:14 AM5/14/11
to greasemon...@googlegroups.com
Fairly trivial to just keep a list of domains you have visited, and drop
out of the script if you get a match. You could use a GM value or local
storage to contain the list.

Kwah

unread,
May 14, 2011, 10:57:33 AM5/14/11
to greasemon...@googlegroups.com
Have you checked whether the page you are loading uses frames or
iframes ('embedded sites')?

If it does, what you see as one page-load may actually be 2 or more
documents loading on the same page. In other words, your script is
most likely running multiple times due to there being more than one
frame on the page that matches your @include and @exclude rules.

Some details are now available on the Greasepot wiki <
http://wiki.greasespot.net/Prevent_Execution_in_Frames > (nb: subject
to change) which gives an example of how to stop your script doing
this (by comparing window.top and window.self).

Regards

> --
> 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.
>
>

Nico Gerwien

unread,
May 14, 2011, 12:02:08 PM5/14/11
to greasemonkey-users
<http://wiki.greasespot.net/Prevent_Execution_in_Frames>

Thanks, that was exactly what i am looking for.

On 14 Mai, 16:57, Kwah <kwa...@gmail.com> wrote:
> Have you checked whether the page you are loading uses frames or
> iframes ('embedded sites')?
>
> If it does, what you see as one page-load may actually be 2 or more
> documents loading on the same page. In other words, your script is
> most likely running multiple times due to there being more than one
> frame on the page that matches your @include and @exclude rules.
>
> Some details are now available on the Greasepot wiki <http://wiki.greasespot.net/Prevent_Execution_in_Frames> (nb: subject
> to change) which gives an example of how to stop your script doing
> this (by comparing window.top and window.self).
>
> Regards
>

emraan

unread,
Jul 9, 2012, 9:08:59 AM7/9/12
to greasemon...@googlegroups.com

Thanks a lot :D solved my Problem \m/

Reply all
Reply to author
Forward
0 new messages