4

I am exactly doing what Brock Adams mentioned here but I am not being able to see alert at all. I have put all my files in same folder where user script exist but some how it is broken and I can't trace it either.

I am on Firefox version 21

Community
  • 1
  • 1
Volatil3
  • 14,253
  • 38
  • 134
  • 263

1 Answers1

26

That linked answer was from 2011, and Greasemonkey has changed a lot since then. (Note, I just now updated that answer to reflect the changes.)

Basically, you need to use @grant directives now. If you looked on Firefox's error console (CtrlShiftJ), you might have seen error messages like:

GM_addStyle is not defined

Here is a bare-bones addition of jQuery-UI to demonstrate the process:

// ==UserScript==
// @name     _YOUR_SCRIPT_NAME
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require  http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js
// @resource jqUI_CSS  http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css
// @grant    GM_addStyle
// @grant    GM_getResourceText
// ==/UserScript==

var jqUI_CssSrc = GM_getResourceText ("jqUI_CSS");

GM_addStyle (jqUI_CssSrc);
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • I did not see that particulr error. It worked fine when I used inline css and assign to _Gm_addStyle. Also while I would like to convert my GM script into FireFox extension, what if GM is not installed on machine, will **GM_** work? – Volatil3 Aug 05 '13 at 07:35
  • I am using GM 0.922 which I downloaded from Mozilla website. Where can I get new one? – Volatil3 Aug 05 '13 at 07:40
  • 1
    I updated GM version. On putting _grant_ I get error, *this.stringbundle is undefined* and it is comong on the line which does not exist either! – Volatil3 Aug 05 '13 at 08:17
  • On the other note, CSS on my local hard disk on same folder of GM script is not being loaded at all – Volatil3 Aug 05 '13 at 09:18
  • Am I going crazy? or is this out of date again? I keep seeing this suggestion, but I'm getting the error: `ReferenceError: GM_getResourceText is not defined` even though I have both marked with `@grant` – isaaclw Jul 24 '19 at 19:21
  • 1
    @isaaclw, If you are using Greasemonkey version 4 or later. [**Don't.**](https://www.greasespot.net/2017/09/greasemonkey-4-for-users.html) – Brock Adams Jul 24 '19 at 20:18