javascript - Greasemonkey @require jQuery 不工作 "Component not available"

标签 javascript jquery firefox-addon greasemonkey

我看过 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/

相关文章:

javascript - 为什么我的 jquery val() 没有从我的选择框中选择实际选择的值?

javascript - 我的循环不会查看数组中的第一项。 Angular js

javascript - ui-scroll - 无法回到列表的开头

javascript - jQuery 没有得到应用

javascript - 使用触发器选择所有复选框 - jquery

javascript - 如何检测 firefox 扩展中的 firefox 启动事件?

html - 如何使用 AdBlock Plus 过滤器隐藏背景

firefox - 使用 firefox 插件重定向请求

javascript - D3 具有负值的直方图

javascript - 使用 Javascript 双三次调整图像大小