我见过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。我已经清除了缓存(除了cookies),并禁用了除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>
我可以在gm_scripts/myscript/目录中看到jquerymin.js。
此外,在安装Greasemonkey脚本时,在控制台中出现此错误是否常见?
Error: not well-formed
Source File: file:///Users/Greg/Documents/myscript.user.js
Line: 1, Column: 1
Source Code:
// ==UserScript==发布于 2010-01-16 23:35:01
好的,所以我更深入地研究了这个问题。我准确地使用了您的脚本,但使用了我们的JQuery版本,使其看起来如下所示:
// ==UserScript==
// @name My Script
// @namespace http://www.google.com
// @description My test script
// @include http://www.google.se/*
// @include http://www.dn.se/*
// @require http://myserver/jquery-1.3.2.js
// ==/UserScript==
GM_log("Hello");这对我来说很好,我猜,google api上的JQuery up缺少一些功能。因为上面的代码运行得很好。还要注意每个url末尾的/*,请将其包括在内。
尝试另一个JQuery并更改urls,它应该可以正常工作。
发布于 2010-02-03 15:01:31
我发现了一种在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;发布于 2010-03-22 09:42:01
我在GM0.8和jQuery1.4.2中尝试处理这个问题时遇到了一些问题,结果发现了这个问题:http://forum.jquery.com/topic/importing-jquery-1-4-1-into-greasemonkey-scripts-generates-an-error
在我看来,这是这个问题的最终答案,以及如何解决它。这个变通方法对我起作用了。
https://stackoverflow.com/questions/2077714
复制相似问题