我看过 the other question on here关于在 Greasemonkey 中加载 jQuery。尝试过该方法后,在我的 ==UserScript==
标签中使用此 require 语句:
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
我仍然在 Firefox 的错误控制台中收到以下错误消息:
Error: Component is not available
Source File: file:///Users/greg/Library/Application%20Support/
Firefox/Profiles/xo9xhovo.default/gm_scripts/myscript/jquerymin.js
Line: 36
这会阻止我的 greasemonkey 代码运行。我已经确定我包含了 jQuery 的 @require
并在安装它之前保存了我的 js 文件,因为所需的文件只在安装时加载。
代码:
// ==UserScript==
// @name My Script
// @namespace http://www.google.com
// @description My test script
// @include http://www.google.com
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// ==/UserScript==
GM_log("Hello");
我在 Macbook Pro Leopard (10.5.8) 的 Firefox 3.5.7 上安装了 Greasemonkey 0.8.20091209.4。我已经清除了缓存(cookie 除外)并禁用了除 Flashblock 1.5.11.2、Web Developer 1.1.8 和 Adblock Plus 1.1.3 之外的所有其他插件。
安装了 Greasemonkey 脚本的 config.xml
:
<UserScriptConfig>
<Script filename="myscript.user.js" name="My Script"
namespace="http://www.google.com" description="My test script" enabled="true"
basedir="myscript">
<Include>http://www.google.com</Include>
<Require filename="jquerymin.js"/>
</Script>
我可以看到 jquerymin.js 位于 gm_scripts/myscript/
目录中。
另外,安装Greasemonkey脚本时,控制台出现这个错误是不是很常见?
Error: not well-formed
Source File: file:///Users/Greg/Documents/myscript.user.js
Line: 1, Column: 1
Source Code:
// ==UserScript==
最佳答案
我发现了一种将它与 jQuery 1.4.1 一起使用的非理想方式——这似乎可以解决问题。这是 new browser sniffing这似乎“打破”了它。
jquery-1.4.1.min.js:
[old] 36: var o=r.createElement("div");n="on"+n;var m=n in o;
[new] 36: var o=r.createElement("div");n="on"+n;var m=true;
jquery-1.4.1.js
[old] 934: var isSupported = (eventName in el);
[new] 934: var isSupported = true;
关于javascript - Greasemonkey @require jQuery 不工作 "Component not available",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2077714/