A [[user script]] is a plain text file with a file extension of <code>.user.js</code>.
Typically a [[metadata block]] is included. Although this is not strictly required '''it is highly recommended'''.
Creation of a [[user script]] can be done with any plain text editor. Upon completion of a script it may be distributed via any server method available or even a specialized user script hosting site such as [http://userscripts.org userscripts.org].
The tricky part of course is what happens between starting a script and when the script is finished.
Manually walking through all the steps will ensure common understanding of what is going on.
== Picking an Editor ==
Most script wrights just use a familiar built in text editor such as Windows Notepad, Linux KDE Kwrite/Kate, Linux Gnome gedit, or Mac OS X TextEdit. However some may not include mono-spaced fonts, syntax highlighting and brace matching. These can be very helpful features when coding.
Begin with creating the text file in a favorite plain text editor. It should contain the [[metadata block]] with at least the [[Metadata_block#.40name|@name]], [[Metadata_block#.40namespace|@namespace]], a brief [[Metadata_block#.40description|@description]] and any appropriate [[Metadata_block#.40include|@include]] and [[Metadata_block#.40exclude|@exclude]] [[include and exclude rules|rules]]. Once this has been completed continuation of writing the actual code may occur. However it is not yet necessary, and can be considered counterproductive for new script wrights. Now the script stub is ready to be installed into [[Greasemonkey]].
== The Editor ==
== Editing the Script ==
As of Greasemonkey 4.0, due to limits in the WebExtension API surface, only an embedded editor is available.
At this point [[Greasemonkey]] has already made a copy of the script installed and placed it in the [[scripts directory]]. Any future page loads which match the [[include and exclude rules]] will execute the script. Close the text editor and optionally delete the original source file.
Next is finding and editing the copy of the script that Greasemonkey is working with.
The script itself is listed in the editor's first tab.
This may be done directly 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.
Any <code>@require</code> or <code>@resource</code> files will be listed in additional tabs.
The first shortcut would be the edit button in the [[Greasemonkey Manual:Manage Dialog|manage dialog]].
Alternately a quick right-click in the [[Greasemonkey Manual:Monkey Menu|monkey menu]] will produce the same results.
Working with the copy of the script that [[Greasemonkey]] has installed, code changes will be immediately available excluding certain changes in the metadata block mentioned [[Metadata block#Caveats|here]].
Press <kbd>Ctrl-S</kbd> (or click the floppy disk icon at top left<!-- TODO: Update screenshot -->) to save any changes.
When all changes are completed, simply save the file and reload any pages that apply.
As of Greasemonkey 4.0, due to limits in the WebExtension API surface, only an embedded editor is available.
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.