I’m trying to add jQuery using Greasemonkey’s @require / @include method, but it doesn’t work. The following error shows up:
Uncaught ReferenceError: $ is not defined (repeated 10 times)
This is my sample code:
// ==UserScript==
// @description Bored, really bored.
// @name MatteoSample
// @namespace MatteoSampleNamespace
// @include *
// @include http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
$(document).slideUp();
How can I fix it?
@icis not a valid meta-rule, so it’s ignored.Use
@requireif you want to load jQuery in your user script.EDIT: In the comments, you said that you’re using Chrome. Chrome does not support the
@requirerule. See also:If you want full Greasemonkey support in Chrome, use Tampermonkey.
Clearing up confusion about User scripts in Chrome
Chrome does not natively support GreaseMonkey. Whenever a
.user.jsfile is loaded, it’s converted to a Chrome extension in form of a Content script.For more information on User scripts in Chrome, see this documentation.
The User script is literally copied into the extension’s directory:
A
manifest.jsonfile is created, based on the meta block. When the User script contains a@includerule, itsmatchesrule will containhttps://*/*andhttp://*/*, because of the too loose@includerule.The contents of the generated
manifest.jsonlooks like: