Cross-browser userscripting
User scripts can be used in other browsers than Firefox. However, the scripting APIs and browser JavaScript support vary. This page documents differences in other environments as compared to Greasemonkey in Firefox.
Contents |
Other browsers
Cross-browser solutions
Google Chrome
Chromium and Google Chrome convert User scripts into Chrome extensions since version 5.
A userscript's Metadata block is parsed, and a manifest file is created.
A copy of the user script is used as a content script.
To discern "real" Chrome extensions from converted user scripts, the "converted_from_user_script" property is added.
Because of this distinction, converted user scripts have access to some GM_* methods.
User scripts in Chrome behave similar to ordinary Greasemonkey scripts, with some exceptions:
- Prior Chrome 13, GM_xmlhttpRequest did not allow cross-origin requests. Since version 13, this is possible, provided that the requested URL matches a @include or @match pattern.
-
unsafeWindowin the converted user script is not equivalent to Greasemonkey's unsafeWindow object. Content scripts in Chrome do not have a direct access to the page's globalwindowobject (look here for more information). - The only fully working API methods are: GM_addStyle, GM_xmlhttpRequest, GM_log and GM_openInTab.
- The following methods are defined, but not implemented (when they're called, a message is logged in the console): GM_getValue, GM_setValue, GM_registerMenuCommand.
- User scripts which implement persistency functions exist, but they cannot emulate the exact behaviour: Cookies, DOM Storage and such are domain-specific. Furthermore, the data is also readable by the page itself, which is a potential security leak.
Another option is to use an external user script manager, such as Tamper Monkey, which brings Greasemonkey / Gecko-specific (E4X and for each loops) features to Chrome.
Internet Explorer
See this blog post for some notes.
IEScripts
IEScripts is part of the IE7Pro add-on for Internet Explorer 6 and 7 only.
A directory of scripts is available at iescripts.org.
Section 5 of their tutorial is entitled "Porting from Firefox GreaseMonkey user scripts" and explains how to compensate for various differences.
Even minimal scripts are not immediately compatible between Greasemonkey and IEScripts since the latter uses the .ieuser.js extension rather than .user.js for user scripts; scripts must be renamed to be installed in the other user script engine.
Trixie
Opera User JavaScript
Opera User JavaScript is supported natively since Opera 8 beta 3. A directory of scripts is available at userjs.org.
Safari
GreaseKit
GreaseKit is a User script manager for Safari 4 for Mac. Unfortunately, GreaseKit removed all GM_* functions in version 1.4 (Possible workaround). The GM_addStyle and GM_log methods were re-added in version 1.7 though [1]. The most recent version was released in 2008, so features which were introduced in Greasemonkey 0.9+ (such as @match) are not included.
NinjaKit
In Safari 5 for Mac/Windows, the NinjaKit extension is preferred over GreaseKit, since it uses Safari 5-specific APIs. The Japanese developer published NinjaKit's source code on Github.
English documentation (based on experience and the source code):
- Download the extension, and install it (by opening NinjaKit.safariextz file with Safari 5+).
- After installation, a new button appears at the left side of the location bar.
- To edit/delete/disable scripts, click on the button. User scripts can be managed at the Script tab.
- By clicking on any link which ends with
.user.js, the "Install Greasemonkey" dialog is triggered. These links have to be present when the document finishes loading.[2]).
Alternatives
Without a user script approach, developers still can modify websites other ways:
- Enter javascript: URLs in the Location Bar or using bookmarklets.
- Bookmarklets are javascript: URLs which have been bookmarked and can be very long. They can execute arbitrary JavaScript on any page, but they require a user to click them, rather than running automatically. They cannot make cross-domain XHRs, but they can preserve state via cookies, or by JSONP.
- Use the browser's DOM Inspector. Firebug has a good tools for disabling or altering CSS/HTML elements.
- Use a full-fledged extension that serves the same purpose. (It is possible to convert much of the code in a GreaseMonkey script to become part of a Firefox extension. This is how GreaseMonkey scripters often "graduate" to extension writers.)
- Use a local HTTP proxy that modifies the HTML, such as Proxomitron. (WebWasher was mentioned here but it appears to have been swallowed by McAfee.)
Related Software
See: http://en.wikipedia.org/wiki/List_of_augmented_browsing_software
Web Annotation
Web Annotation is one of the things made possible by user scripts. Some applications concentrate purely on Web Annotation and collaboration, for example SlideSpace, Diigo and Trailfire.
Firefox Extensions
- AlchemyPoint combines a Firefox/Flock extension with a client side Proxy Server to allow for manipulation of web content, scraping of data from websites, detection/parsing of microformats, mashup etc.
- Chickenfoot is a Firefox extension that aims to enable both end-user programmers and hackers to script interactions on the Web.
- iMacros for Firefox is a Firefox extension that allows the user to record and replay so called "Internet Macros" for web automation, web scraping or web testing.
- Platypus is a Firefox extension that lets you interactively modify any Web page from your browser, and optionally to save those transformations as a Greasemonkey script so that they'll be repeated the next time you visit the page.
- Stylish is a Firefox extension that allows for client-side manipulation of webpage content through Cascading Style Sheets.
- Firebug is a developers extension that allows arbitrary real time changes to a page's DOM
- Bubbles is the first Site-Specific-Browser, and it uses JS injection of user-scripts, very much like Greasemonkey.
- Jetpack allows users to write scripts which interact with the Firefox API, making them more powerful like extensions, for example by adding new GUI elements. Editing and testing of jetpacks can be done live.
- Mason is a simple yet powerful system which can activate and interact before resources are even loaded. Requires knowledge of RegExp.
Proxy Level
- GrimeApe is provided through a proxy which injects a few <SCRIPT> tags into web pages. GrimeApe currently includes the Base2 JS library, which attempts to fix non-standards compliance for all browsers.
- Monkeygrease is a Java Servlet that alters the output of a closed-source Java web application before its output is sent to the client.
- Proxomitron, available since late 1990s, predates JavaScript active browsing and provides a similar function for all browsers using a regexp-like matching language.
- Proximodo, inspired by- and interoperable with proxomitron, is an open source, client side proxy server that allows page content manipulation.
- Privoxy is an open source, client side proxy server that allows manipulation of page content available in many OS flavors.
- MouseHole is a client side proxy server that allows manipulation of page content using Ruby.
- Muffin is a Java open-source stand alone proxy server that allows manipulation of page content (usually client-side, but sports a web interface in addition to a Swing GUI for configuration).
- BFilter is an open source, client side proxy server that allows manipulation of page content available in many OS flavors.
- Scone is an open source stand alone proxy server (client and server side) that allows any manipulation of transferred web resources. It also provides an personal web crawler, user action logging as well as an mysql persistence component.
References
- ↑ GreaseKit Changes
- ↑ "Links have to be present when the document finishes loading." NinjaKit's source code on Github, grease.js, Line 93 and line 52