Greasemonkey
Encyclopedia
Greasemonkey is a Mozilla Firefox
Mozilla Firefox
Mozilla Firefox is a free and open source web browser descended from the Mozilla Application Suite and managed by Mozilla Corporation. , Firefox is the second most widely used browser, with approximately 25% of worldwide usage share of web browsers...

 extension that allows users to install scripts
Scripting language
A scripting language, script language, or extension language is a programming language that allows control of one or more applications. "Scripts" are distinct from the core code of the application, as they are usually written in a different language and are often created or at least modified by the...

 that make on-the-fly
On the fly
-Colloquial usage:In colloquial use, on the fly means something created when needed. The phrase is used to mean:# something that was not planned ahead# changes that are made during the execution of same activity: ex tempore, impromptu.-Automotive usage:...

 changes to HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....

 web page
Web page
A web page or webpage is a document or information resource that is suitable for the World Wide Web and can be accessed through a web browser and displayed on a monitor or mobile device. This information is usually in HTML or XHTML format, and may provide navigation to other web pages via hypertext...

 content on the DOMContentLoaded event
DOM Events
DOM events allow event-driven programming languages like JavaScript, JScript, ECMAScript, VBScript and Java to register various event handlers/listeners on the element nodes inside a DOM tree, e.g. HTML, XHTML, XUL and SVG documents....

, which happens immediately after it is loaded in the browser (also known as augmented browsing
Augmented browsing
Augmented browsing describes the experience of using a system that can automatically augment or improve the information in web pages. For example, augmented browsing could be used to automatically add definitions for all scientific or technical keywords that occur in a document...

).

As Greasemonkey scripts are persistent, the changes made to the web pages are executed every time the page is opened, making them effectively permanent for the user running the script.

Greasemonkey can be used for adding new functions to web pages (for example, embedding price comparisons within shopping sites), fixing rendering bugs, combining data from multiple webpages, and numerous other purposes.

Technical details

Greasemonkey user scripts are written in JavaScript
JavaScript
JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

 and manipulate the contents of a web page using the Document Object Model
Document Object Model
The Document Object Model is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. Aspects of the DOM may be addressed and manipulated within the syntax of the programming language in use...

 interface. Scripts are generally written to be either page-specific or domain-specific (applying to all pages within a domain) but may also be tagged to apply to all domains for global browser enhancements. userscripts.org maintains a database of Greasemonkey scripts, and for each, lists the URL
Uniform Resource Locator
In computing, a uniform resource locator or universal resource locator is a specific character string that constitutes a reference to an Internet resource....

s of web pages to which the script pertains. Users of Greasemonkey can write or download scripts and save them to their own personal library. When users visit a website matching a script in their personal script library, Greasemonkey invokes the relevant scripts, which can modify a webpage in any way which JavaScript allows—with certain Greasemonkey security restrictions. Greasemonkey scripts can also poll external HTTP resources via a non-domain-restricted XMLHTTP
XMLHttpRequest
XMLHttpRequest is an API available in web browser scripting languages such as JavaScript. It is used to send HTTP or HTTPS requests directly to a web server and load the server response data directly back into the script. The data might be received from the server as XML text or as plain text...

 request, allowing external content to be merged with the original page content. Scripts are named somename.user.js, and Greasemonkey offers to install any such script when a URL ending in that suffix is requested. Greasemonkey scripts contain optional metadata, which specifies the name of the script, a description, relevant resources to the script, a namespace
Namespace
In general, a namespace is a container that provides context for the identifiers it holds, and allows the disambiguation of homonym identifiers residing in different namespaces....

 URL used to differentiate identically named scripts, and URL patterns for which the script is intended to be invoked or not.

Writing a Greasemonkey script is similar to writing JavaScript for a web page, with some additional allowances such as cross-site XMLHttpRequest
XMLHttpRequest
XMLHttpRequest is an API available in web browser scripting languages such as JavaScript. It is used to send HTTP or HTTPS requests directly to a web server and load the server response data directly back into the script. The data might be received from the server as XML text or as plain text...

s. Compared to writing a full-fledged Firefox extension, user scripting is a very modest step up in complexity from basic web programming. However, Greasemonkey scripts are limited due to security restrictions imposed by Mozilla's XPCNativeWrappers. For example, Greasemonkey scripts do not have access to many of Firefox's components, such as the download manager, I/O processes
Input/output
In computing, input/output, or I/O, refers to the communication between an information processing system , and the outside world, possibly a human, or another information processing system. Inputs are the signals or data received by the system, and outputs are the signals or data sent from it...

 or its main toolbars. Additionally, Greasemonkey scripts run per instance of a matching webpage. Because of this, managing lists of items globally is difficult. However, script writers have been using cookies and Greasemonkey even offers APIs such as GM_getValue and GM_setValue to overcome this.

Compatibility

Greasemonkey is available for Firefox, Flock
Flock (web browser)
Flock was a web browser that specialized in providing social networking and Web 2.0 facilities built into its user interface.Earlier versions of Flock used the Gecko HTML rendering engine by Mozilla....

 and Epiphany
Epiphany (web browser)
Epiphany is an open source web browser for the GNOME desktop environment. The browser is a descendant of Galeon, and was created after developer disagreements about Galeon's growing complexity...

. The Epiphany Greasemonkey extension is part of the Epiphany-extensions package. However, this extension is not fully compatible as of release 2.15.1, since some Greasemonkey API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

 functions (e.g. GM_getValue) are unsupported. There are also custom versions for SeaMonkey
SeaMonkey
SeaMonkey is a free and open source cross-platform Internet suite. It is the continuation of the former Mozilla Application Suite, based on the same source code...

 and Songbird
Songbird (software)
Songbird is a free and open source software audio player and web browser, with a stated mission "to incubate Songbird, the first Web player, to catalyze and champion a diverse, open Media Web."...

.

Equivalents for other browsers

Versions 8 and upwards of Opera
Opera (web browser)
Opera is a web browser and Internet suite developed by Opera Software with over 200 million users worldwide. The browser handles common Internet-related tasks such as displaying web sites, sending and receiving e-mail messages, managing contacts, chatting on IRC, downloading files via BitTorrent,...

 also have user scripting functionality and are capable of running many Greasemonkey user scripts.

For Internet Explorer
Internet Explorer
Windows Internet Explorer is a series of graphical web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems, starting in 1995. It was first released as part of the add-on package Plus! for Windows 95 that year...

, similar functionality is offered by IE7Pro
IE7Pro
IE7Pro is an add-on for Internet Explorer 6, 7, 8, and 9 that aims to enhance the feature set provided by the browser. IE7Pro adds features such as tab enhancement, an ad blocker and flash blocker, mouse gestures, inline search, privacy enhancements, online bookmark service, Greasemonkey-like user...

, Sleipnir
Sleipnir (web browser)
Sleipnir is a tabbed web browser developed by Fenrir Inc. The browser is known for its high level of user customization and is one of the few browsers to still support Windows 98...

, iMacros
IMacros
iMacros is an extension for the Mozilla Firefox, Google Chrome, and Internet Explorer web browsers which adds record and replay functionality similar to that found in web testing and form filler software. The macros can be combined and controlled via JavaScript. Demo macros and JavaScript code...

, Trixie.

, Chrome
Google Chrome
Google Chrome is a web browser developed by Google that uses the WebKit layout engine. It was first released as a beta version for Microsoft Windows on September 2, 2008, and the public stable release was on December 11, 2008. The name is derived from the graphical user interface frame, or...

 has limited "native support" for Greasemonkey scripts. They are internally converted to extensions, and are managed as such. Chrome honours the @include and @exclude directives, and introduces the @match objective as a simplified way to select specific domains/pages specified. In Chrome, scripts that use Firefox-specific functionality will break, and several Greasemonkey features are unavailable.

On Safari
Safari (web browser)
Safari is a web browser developed by Apple Inc. and included with the Mac OS X and iOS operating systems. First released as a public beta on January 7, 2003 on the company's Mac OS X operating system, it became Apple's default browser beginning with Mac OS X v10.3 "Panther". Safari is also the...

 (and other WebKit
WebKit
WebKit is a layout engine designed to allow web browsers to render web pages. WebKit powers Google Chrome and Apple Safari and by October 2011 held over 33% of the browser market share between them. It is also used as the basis for the experimental browser included with the Amazon Kindle ebook...

 applications), there is a SIMBL
SIMBL
SIMBL , is an application enhancement loader for Mac OS X developed by Mike Solomon. It helps third-party developers modify and add functionality to applications developed with the Cocoa environment without access to the source code...

-managed plug-in called GreaseKit. Since the release of Safari 5 there is an extension called NinjaKit that uses the new API interface. Fluid is a site-specific browser with integrated GreaseKit.

See also

  • List of augmented browsing software
  • List of Firefox extensions
  • ShiftSpace
    Shiftspace
    ShiftSpace is an open-source metaweb or web annotation application and framework that allows altering web pages with different tools. The tagline of the application is "an open source layer above any web page"...

    , an extensible platform for annotating and modifying web content, built on top of Greasemonkey

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK