views:

101

answers:

2

I really really want to write a GreaseMonkey extension.

I have written a lot of javascript in my life.

I am looking for a guide that will tell me quickly, what exactly the GreaseMonkey environment is and does, from the perspective of someone who is familiar with everything going on in browser based Javascript.

I.e. no platitudes about how best to do things, or what has been done in the past, just a plain and simple, "this is what is going to happen to your code. " "This is the environment it will be executed in."

And I can't find one....

+3  A: 

Dive into Greasemonkey is probably the best reference.

Also, Greasemonkey official docs may be helpful.

fserb
The problem with that is that it just shows me how to do some pre-defined tasks. I want to be able to know reasonably well what is going to happen when I write a script, or include jquery.Essentially, what the precise differences are going be between greasemonkey and in page scripts.
AlexH
Could you be a little more specific? The basic difference between GM and an in-page script is that GM scripts are run inside a sandbox without direct access to the "window" (if you really need, you can try the unsafeWindow object. Except for that difference, the only other thing I can think of is access to the GM_* functions.
fserb
Is there anywhere that I can find a terse listing of the GM_* functions? Perhaps alongside a reccomended "safe" way of accessing the window?
AlexH
Updated response.
fserb
+1  A: 

To write userscripts, you start with a js file that is named like yourfile.user.js. Sample content below:

// ==UserScript==
// @name         script-name
// @version      0.1
// @date         yyyy-mm-dd
// @description  description-of-the-script
// @author       John Doe
// @namespace    http://www.foobar.com
// ==/UserScript==

(function (){
  // your js code here

  // this is how you access the global vars in the page
  unsafeWindow.foo = bar;
});

With greasemonkey activated in Firefox browser, when you open this js file in browser, it will prompt you to install it. Install and refresh page to execute it.

For more details, see the link shared by fserb.

Joy Dutta