Greasemonkey Manual:Editing: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Greasemonkey Manual TOC}}
{{Greasemonkey Manual TOC}}
== Vikas Bhadu ==
== User Script Flow ==
== User Script Flow ==


Line 6: Line 8:
Typically a [[Metadata Block]] is included.  Although this is not strictly required '''it is highly recommended'''.
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].
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 Vikas-Bhadu.org].


The tricky part of course is what happens between starting a script and when the script is finished.
The tricky part of course is what happens between starting a script and when the script is finished.

Revision as of 09:36, 5 November 2011


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

Vikas Bhadu

User Script Flow

A user script is a plain text file with a file extension of .user.js. 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 Vikas-Bhadu.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 authors use a familiar built in text editor such as Windows Notepad, Linux KDE Kwrite/Kate, Linux Gnome gedit, or Mac OS X TextEdit. Many other editors are available that provide features to make programming easier. For more information, and choices, see Wikipedia's comparison of text editors.

Creating the Script

Begin with creating the text file in a favorite plain text editor. It should contain the Metadata Block with at least the @name, @namespace, a brief @description and any appropriate @include and @exclude rules. Once this has been completed, the writing of the actual code may begin. Although it may make little sense with no code, the script stub is ready to be installed into Greasemonkey.

Editing the Script

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. This may be done directly as explained in the FAQ, or by one of two shortcuts Greasemonkey provides. The first shortcut would be the edit button in the manage dialog. Alternately a quick right-click in the monkey menu will produce the same results.

When working with the copy of the script that Greasemonkey has installed, code changes will be immediately available. Simply save the file and reload any appropriate page.

Changing the Editor

As of Greasemonkey 0.9, simply open the Options dialog (Tools, Add-ons, Greasemonkey, Options (or Preferences)) and click the "Change Editor" button. Pick an executable text editor program with the resulting file picker dialog.

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.