Greasemonkey Manual:Editing: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
(add editors, rename)
No edit summary
 
(83 intermediate revisions by 28 users not shown)
Line 1: Line 1:
__NOTOC__
{{Greasemonkey Manual TOC}}
{{Greasemonkey Manual TOC}}
__NOTOC__
== User Script Flow ==
First: a [[user script]] is only a plain text file with the extension <code>.user.js</code>.
Usually, a [[metadata block]] is included, although this is not strictly required.
You may create a [[user script]] with any text editor.
When you're done, distribute it via whatever means you like.
For example, you may place it on a web server.
The tricky part of course is what happens between when you start and when the script is finished.
Let's walk through all the steps, manually, to make sure we understand what is going on.
== Creating the Script ==
First, create the text file.
It should contain the [[metadata block]] with name, namespace, and any appropriate [[include and exclude rules]] and nothing more.
At this point, you may begin with any of the script itself, but it is not yet necessary, and likely is counterproductive.
Now, install this stub script into [[Greasemonkey]].


== Editing the Script ==
== The Editor ==


At this point, [[Greasemonkey]] will make a copy of the script, into the [[scripts directory]], and any future page loads (which match the [[include and exclude rules]]) will have that script run.
As of Greasemonkey 4.0, due to limits in the WebExtension API surface, only an embedded editor is available.
At this point, though, "that script" is the copy that [[Greasemonkey]] made, '''not''' the original file you started with.
It is probably a good idea now to delete the original file you created just moments ago, to reduce confusion.


Next, find and edit the copy of the script that [[Greasemonkey]] is working with.
[[Image:Editor.png|thumb|382px|frame|center|Greasemonkey's script editor]]
You may do this yourself, as explained in the [[FAQ#Yes.2C_but_how_can_I_edit_a_script_without_going_through_Greasemonkey.3F|FAQ]], or by one of two shortcuts [[Greasemonkey]] provides.
The first shortcut would be the edit button in the [[Greasemonkey Manual:Manage Dialog|manage dialog]].
Alternately, you can use the right-click shortcut in the [[Greasemonkey Manual:Monkey Menu|monkey menu]].


Now that you are working with the copy of the script that [[Greasemonkey]] has installed, your changes will be immediately available (except for changes in metadata block, as mentioned [[Metadata block#Caveats|here]]).
The script itself is listed in the editor's first tab.
When you make a change to the script, simply save the file and reload the page that it applies to, and this new version of the script will be run.
Any <code>@require</code> or <code>@resource</code> files will be listed in additional tabs.


=== Picking an Editor ===
Press <kbd>Ctrl-S</kbd> (or click the floppy disk icon at top left<!-- TODO: Update screenshot -->) to save any changes.
Most scriptwrights just use Windows Notepad, which is commonly found in <code>C:\Windows\System32\notepad.exe</code>. However, notepad isn't natively fixed-width, and doesn't have syntax highlighting or brace matching, two very helpful features when coding. Here is a list of the most popular script editing programs:
* Notepad++
* EditPad Pro
* Adobe Dreamweaver CS4
* Notepad2
* Eclipse
* Aptana
* PSPad
* GVim


== That's It! ==
== That's It! ==

Latest revision as of 00:03, 18 April 2024


Greasemonkey Manual
Using Greasemonkey
Installing Scripts
Monkey Menu
Getting Help
User Script Authoring
Editing
Environment
API

The Editor

As of Greasemonkey 4.0, due to limits in the WebExtension API surface, only an embedded editor is available.

Greasemonkey's script editor

The script itself is listed in the editor's first tab. Any @require or @resource files will be listed in additional tabs.

Press Ctrl-S (or click the floppy disk icon at top left) to save any changes.

That's It!

Writing scripts for Greasemonkey is not hard. What can get difficult, however, is working with the quirks and limitations that the script runs under; Some things that work perfectly in a normal web page, copied and pasted directly to a user script suddenly fail. It's important to know how the environment the scripts run in works.