3

I'm using Firefox 2.0.0.11 and Greasemonkey 0.8.x and the latest jQuery version (1.3.2) that works with Greasemonkey 0.8.
I try to load this Userscript:

// ==UserScript==
// @name        TEST
// @include     *
// @require     jquery.min.js
// @grant       GM_getValue
// ==/UserScript==

$(document).ready(function(){
    alert('jQuery!');
});     

but I receive the error:

Error: $ is not defined
Source File: file:///G:/Firefox/Data/profile/gm_scripts/huhu/huhu.user.js
Line: 8

I know that I have to update this old browser. But it's not possible. I have to work with that!

I want to load jQuery code on a local PC with no internet connection. I have copied jquery.min.js in the same folder where the userscript is.

G:/Firefox/Data/profile/gm_scripts/huhu/jquery.min.js

Any ideas where the problem is?

Regards, Bernte

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
bernte
  • 1,184
  • 2
  • 19
  • 34

1 Answers1

3

There are two ways to install a Greasemonkey script, from a local drive, such that jQuery will work.
But, first, here are the...

Prerequisites common to both methods:

  1. Older versions of Greasemonkey (and Firefox) got confused easily. So, use Greasemonkey's Script Manager to uninstall any old versions of the script.

  2. Go to the gm_scripts folder, in your Profile Folder, and physically delete the folder for your script, if it's present.

  3. Make sure your script source-code is in a file with a user.js extension. EG: Hello World.user.js

  4. Make sure your script source-code is in a folder that is not in a system TMP or temp folder. For example, place the source file in C:\My GM scripts\.

  5. Likewise, this is not, and do not use, any folder in the Firefox Profile Folder tree.

  6. When in doubt, or if things appear "flaky", restart Firefox.


Method 1, the computer has internet access:

  1. Merely point the @require at Google's copy of the correct jQuery version. For GM 0.8, it should be no later than jQuery 1.3.2.

    // ==UserScript==
    // @name     Hiya Ma
    // @include  http://stackoverflow.com/*
    // @require  http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
    // ==/UserScript==
    
    $("body").prepend ('<div>Hello world!</div>');
    


  2. Use the Firefox, Open File menu (CtrlO) to open the source file. (EG: C:\My GM scripts\Hello World.user.js)

    Or:
    Drag-and-drop the source file to any open Firefox tab.

  3. Greasemonkey will prompt to install the script. Follow the prompts.


Method 2, the computer cannot access the web:

  1. Download the appropriate jQuery version (1.3.2 in this case), and save it as jquery.min.js, in the same folder as the script source (C:\My GM scripts\, in this example).

  2. Do not use any path in the @require directive:

    // ==UserScript==
    // @name     Hiya Ma
    // @include  http://stackoverflow.com/*
    // @require  jquery.min.js
    // ==/UserScript==
    
    $("body").prepend ('<div>Hello world!</div>');
    


  3. Install the script as in steps 2 and 3 of Method 1. You do not need to open or drag the jQuery file.


Also Note:

  1. G:/Firefox/Data/profile/gm_scripts/huhu/jquery.min.js look like a Firefox profile directory. You place no files here. Greasemonkey will copy and rename files as appropriate.

  2. @grant is not supported until Greasemonkey version 1.0. Do not use it here.

  3. $(document).ready() is not needed here, nor in most GM scripts. Greasemonkey fires at the correct time by default.

  4. These methods were verified against Firefox 2.0.0.20 and Greasemonkey 0.8.20100408.6, but they pretty much apply to all versions of FF+GM until GM 1.0.


What to do if you get an `NS_ERROR_FILE_ACCESS_DENIED` error:

This error was not uncommon with older versions of Greasemonkey. The two most frequent causes were poor temp-file housekeeping (by FF/GM) and Firefox profile corruption.

Do the following to remedy this in most cases:

  1. Repeat the prerequisites, listed above.

  2. Purge the system temp folder(s) of anything that resembles the script source file, or any @required files, or any @resourced files.

    In this example, look for hiya_ma.user.js and jquerymin.js, in particular.

    In Windows, the temp folder(s) have the address(es): %TMP% and %TEMP%.

  3. In the gm_scripts folder, make sure that config.xml has no references to deleted or missing scripts. If there are no (other) scripts, delete config.xml.

  4. If all else fails, uses Firefox's Profile Manager to create a new profile and reinstall your scripts there.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • hi brock.. i used your method 2. i created a folder C:\userscripts\ where i copied jquery.min.js (1.32) and Hiya Ma.user.js inside. i uninstalled all userscripts in greasemonkey and restarted firefox 2.0.0.11. then i dragged&dropped Hiya Ma.user.js inside the firefox window! after press install i recieve the following error http://tinyurl.com/96wksag i think that firefox 2.0.0.11 does not handle that, right? – bernte Sep 09 '12 at 11:53
  • i tried it with 2.0.0.20 as you described it! and it works!! seems to give problems with 2.0.0.11 – bernte Sep 09 '12 at 13:37
  • It is extremely unlikely that the problem is between 2.0.0.11 and 2.0.0.20. That error looks like what used to happen sometimes with FF/GM. It only worked with 2.0.0.20 because that had the side effect of changing or refreshing the FF profile. See the new section in the answer. – Brock Adams Sep 09 '12 at 23:38