Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've seen the other question on here about loading jQuery in a Greasemonkey. Having tried that method, with this require statement inside my ==UserScript== tags:

// @require    http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js

I still get the following error message in Firefox's error console:

Error: Component is not available
Source File: file:///Users/greg/Library/Application%20Support/
       Firefox/Profiles/xo9xhovo.default/gm_scripts/myscript/jquerymin.js
Line: 36

This stops my greasemonkey code from running. I've made sure I included the @require for jQuery and saved my js file before installing it, as required files are only loaded on installation.

Code:

// ==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");

I have Greasemonkey 0.8.20091209.4 installed on Firefox 3.5.7 on my Macbook Pro, Leopard (10.5.8). I've cleared my cache (except cookies) and have disabled all other plugins except Flashblock 1.5.11.2, Web Developer 1.1.8 and Adblock Plus 1.1.3.

My config.xml with my Greasemonkey script installed:

<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>

I can see jquerymin.js sat in the gm_scripts/myscript/ directory.

Additionally, is it common for this error to occur in the console when installing a Greasemonkey script?

Error: not well-formed
Source File: file:///Users/Greg/Documents/myscript.user.js
Line: 1, Column: 1
Source Code:
   // ==UserScript==
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
372 views
Welcome To Ask or Share your Answers For Others

1 Answer

I found a non-ideal way to use it with jQuery 1.4.1 -- this seems to fix it. It's the new browser sniffing that seems to "break" it.

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...