Search code examples
cssgreasemonkey

Local CSS resource in GM script not recognized


I have a GM script that contains the following:

...
// @grant          GM_addStyle
...
// @resource       css my.css
...

GM_addStyle(GM_getResourceText('css')) // the error occurs here

...

GM threw out this script from its config.xml (that happens occasionally) recently, so:

  • I renamed the scripts folder to /*.OLD,
  • created a new script with the same name,
  • copied all files (*.css, etc.) from *.OLD to the new script folder, except the script file (<name>.user.js) itself,
  • C&Ped the code from /*.OLD/<name>.user.js to the newly created script file.

Now it runs again but throws an:

Error: No resource with name "css"

Why this? The resource is declared above and it exists in the script's folder. (There's also no upper/lower case difference between the declaration and the actual file name.)

UPDATE

Windows 7 Prof. SP 1 (64-Bit), FF 56.0.2 (64-Bit), GM 3.17


Solution

  • Greasemonkey, pre version 4, didn't just go by the xml file. It also used a *.db file, and also scanned the scripts folder on startup. It hasn't been necessary to mess with either config file for years.

    Anyway, the method from the question is just about the only way to reinstall a script that didn't work on that GM version. You usually can't just copy a @require or @resource back on corrupted config. Greasemonkey remains confused.

    This should fix it:

    1. Copy all required, local files, from the offending script's directory to a working directory that is in neither the system temp path, nor the gm_scripts folder.
      I recommend using a folder tree, or Git repository, etc. to preserve/track the scripts outside of Firefox.
    2. Using Greasemonkey's script manager, uninstall the old script (if present).
    3. Shut down Firefox. Use Task Manager to ensure that no Firefox processes remain in memory.
    4. In the working folder, that has the *.user.js file, ensure that all files that are @required or @resourced, locally, are present.
      If the @require or @resource path points to a viable server path, then the file need not be on the local drive (Greasemonkey will refetch it, once, on script install).
    5. Restart Firefox.
    6. From windows explorer, drag-and-drop the *.user.js file onto Firefox. This should prompt it to install the script.
    7. On confirming install, Firefox will correctly copy the local files (and fetch any network files) and the script should run correctly.




    Extra credit: Since the current versions of Firefox (57+) and Greasemonkey (4+) are severely crippled and dysfunctional, consider migrating to Tampermonkey and a better browser. In fact, Greasemonkey itself recommends migrating to Tampermonkey or Violentmonkey.

    So far, I've found the UR Browser to be both the most extensible and stable, without the evil "grabbyness" of Chrome. (Opera breaks more scripts/extensions; Vivaldi is promising but buggy; Others have assorted issues.)