|
Free Open Book
Sams Teach Yourself JavaScript in 24 Hours |
Introducing GreasemonkeySo far in this book, you've been using JavaScript to work on your own sites. In this hour, you'll take a break from that and learn about a way to use JavaScript on other people's sites. Greasemonkey is an extension for the Firefox browser that enables user scripts. These are scripts that run as soon as you load a page and can make changes to the page's DOM. A user script can be designed to work on all web pages, or only to affect particular sites. Here are some of the things user scripts can do:
As a simple example, a user script called Linkify is provided with Greasemonkey. It affects all pages you visit and turns unlinked URLs into hyperlinks. In other words, the script looks for any string that resembles a URL in the page, and if it finds a URL that is not enclosed in an <a> tag, it modifies the DOM to add a link to the URL. Greasemonkey scripts can range from simple ones such as Linkify to complex scripts that add a feature to the browser, rearrange a site to make it more usable, or eliminate annoying features of sites such as pop-up ads. Keep in mind that Greasemonkey doesn't do anything to the websites you visitit strictly affects your personal experience with the sites. In this way, it's similar to other browser customizations, such as personal style sheets and browser font settings. By the Way Greasemonkey was created in 2004 by Aaron Boodman. Its official site is http://greasemonkey.mozdev.org/. At this writing, the current version of Greasemonkey is 0.6.4. The current developers are Aaron Boodman and Jeremy Dunck. Installing Greasemonkey in FirefoxGreasemonkey works in Firefox for Windows, Macintosh, and Linux platforms. You can install it by visiting the Greasemonkey site and running the installer. Start at http://greasemonkey.mozdev.org/ and follow these steps:
By the Way When you first install Greasemonkey, the extension doesn't do anythingyou'll need to install one or more user scripts, as described in the next section, to make it useful. Turnabout for Internet ExplorerGreasemonkey was written as a Firefox extension, and does not work on other browsers. Fortunately, there's an alternative for those who prefer Internet Explorer: Turnabout, from Reify, is an open-source add-on for Internet Explorer that supports user scripts. Turnabout is available for free from its official site at http://www.reifysoft.com/turnabout.php. Two versions are available:
Turnabout supports most of Greasemonkey's features, and user scripts for Greasemonkey often work with Turnabout Advanced without modification. The only potential problem is with differences in JavaScript and in the DOM between Internet Explorer and Firefox. If you follow the same cross-browser coding practices you learned throughout this book, there's a good chance you can make a user script that works on both platforms. Other BrowsersAlthough Greasemonkey itself is still relatively new software, user script features have also appeared for other browsers. Along with Turnabout for IE, two other browsers can support user scripts:
User Script SecurityBefore you get into user scripting, a word of warning: Don't install a script unless you understand what it's doing, or you've obtained it from a trustworthy source. Although the Greasemonkey developers have spent a great deal of time eliminating security holes, it's still possible for a malicious script to cause you troubleat the very least, it could send information about which sites you visit to a third-party website. To minimize security risks, be sure you're running the latest version of Greasemonkey or Turnabout. Only enable scripts you are actively using, and limit scripts you don't trust to specific pages so they don't run on every page you visit. |
Main Menu |
| 500 Juegos Gratis | 500 Giochi Gratis | 500 Jeux Gratuits | 500 Jogos Gratis | 500 Kostenlose Spiele |