@ic
不是有效的元规则,因此会被忽略。
Use @require如果你想在你的用户脚本中加载 jQuery。
// ==UserScript==
// @name Foo
// @namespace Bar
// @include *
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
编辑:在评论中,您说您正在使用Chrome。 Chrome 确实如此not支持@require
规则。也可以看看:
- 油脂点维基:跨浏览器用户脚本
- 堆栈溢出:为什么 jQuery 在 Chrome 用户脚本 (Greasemonkey) 中不起作用?
- 堆栈溢出:如何在 Google Chrome 的 Greasemonkey 脚本中使用 jQuery?
如果您想在 Chrome 中获得完整的 Greasemonkey 支持,请使用捣固猴.
消除有关 Chrome 中用户脚本的混乱
Chrome 确实如此not原生支持 GreaseMonkey。每当一个.user.js
文件加载后,它会转换为 Chrome 扩展形式内容脚本.
有关 Chrome 中的用户脚本的更多信息,请参阅本文档.
用户脚本实际上被复制到扩展的目录中:
// ==UserScript==
// @name Foo
// @namespace Bar
// @include *
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
alert(typeof $)
A manifest.json文件是根据元块创建的。当用户脚本包含@include
规则,其matches
规则将包含https://*/*
and http://*/*
,因为太松@include
rule.
生成的内容manifest.json
好像:
{
"content_scripts": [ {
"exclude_globs": [ ],
"include_globs": [ "*" ],
"js": [ "script.js" ],
"matches": [ "http://*/*", "https://*/*" ],
"run_at": "document_idle"
} ],
"converted_from_user_script": true,
"description": "",
"key": "+.... some key ...=",
"name": "Foo",
"version": "1.0"
}