How to execute JQuery commands from GM user scripts?

82 views
Skip to first unread message

Ben Stover

unread,
Apr 4, 2012, 5:41:24 AM4/4/12
to Greasemonkey Users
In a previous post I asked how to delete a whole div pane like

<div id="foobar">
....
</div>

and an answer was:

$("#foobar").remove();

Thank you.

I wrote this statement into a user script

myscript.user.js

and installed it on my current Firefox.

However when I called the web page then the div pane remains and is not deleted.

Why?

I assume that I cannot call JQuery statements directly from *.user.js scripts.

How else can I call them?

So do I have to wrap them somehow:

CallJQeury("$("#foobar").remove();");

Ben


Tei

unread,
Apr 4, 2012, 5:53:34 AM4/4/12
to greasemon...@googlegroups.com
On 4 April 2012 11:41, Ben Stover <bxst...@yahoo.co.uk> wrote:
> In a previous post I asked how to delete a whole div pane like
>
> <div id="foobar">
> ....
> </div>
>
> and an answer was:
>
> $("#foobar").remove();
>
..

> I assume that I cannot call JQuery statements directly from *.user.js scripts.
>
> How else can I call them?
>

Before installing the script, you need a line like this in the meta
data description of the userscript.

// @require
http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js

more info: http://wiki.greasespot.net/Third-Party_Libraries#jQuery

If you have already installed the script, you need to uninstall and
install again, since required libraries are only downloaded on
installation.

--
--
ℱin del ℳensaje.

Anthony Lieuallen

unread,
Apr 4, 2012, 8:57:05 AM4/4/12
to greasemon...@googlegroups.com
On Wed, Apr 4, 2012 at 5:53 AM, Tei <oscar...@gmail.com> wrote:
If you have already installed the script, you need to uninstall and
install again, since required libraries are only downloaded on
installation.

That has not been true for a while.

http://wiki.greasespot.net/Version_history#0.9.0

"Live in-place editing for the entire script, including metadata (@name, @require, @include, @exclude, etc.)."

dindog

unread,
Apr 4, 2012, 11:39:44 AM4/4/12
to greasemonkey-users
If you script is meant to do some trivial things, and the page itself
has JQuery, you can try unsafeWindow to access the page window object.
e.g. unsafeWindow.$("#foobar").remove();

On Apr 4, 8:57 pm, Anthony Lieuallen <arant...@gmail.com> wrote:

Ben

unread,
Apr 5, 2012, 9:21:54 AM4/5/12
to greasemon...@googlegroups.com
Ok what about if The library is already loaded into FF because another script needs it?
 
Is there a JQuery library-per-Firefox-instance or one library-per-Greasemonkey-Script?
Reply all
Reply to author
Forward
0 new messages