How can I use jQuery in Greasemonkey?

Keira Nighly picture Keira Nighly · May 13, 2009 · Viewed 121k times · Source

I tried putting this line but it doesn't work:

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

jQuery doesn't work in Greasemonkey at all. Is there other way to use jQuery in Greasemonkey?

--

For all the people who have the same problem, you must upload the file to greasespot then install it from there.

The Create New Script option wouldn't work!

Answer

Rob Kennedy picture Rob Kennedy · May 13, 2009

Perhaps you don't have a recent enough version of Greasemonkey. It was version 0.8 that added @require.

// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js 

If you don't have 0.8, then use the technique Joan Piedra describes for manually adding a script element to the page.

Between version 0.8 and 0.9, @require is only processed when the script is first installed. If you change the list of required scripts, you need to uninstall your script and reinstall it; Greasemonkey downloads the required script once at installation and uses a cached copy thereafter.

As of 0.9, Greasemonkey behavior has changed (to address a tangentially related issue) so that it now loads the required scripts after every edit; reinstalling the script is no longer necessary.