Firefox:Dive Into Greasemonkey/2.1. Hello World
Mozilla中文Wiki
您的位置:Dive Into Greasemonkey → 您的第一个用户脚本 → Hello World
[编辑]
2.1. Hello World
我们步入 Greasemonkey 美妙世界的万里长征将从第一步开始, 所有读过技术手册的读者都会很熟悉这一步:让您的电脑打出“Hello world”。
例子: helloworld.user.js (http://diveintogreasemonkey.org/download/helloworld.user.js)
// Hello World! example user script
// version 0.1 BETA!
// 2005-04-22
// Copyright (c) 2005, Mark Pilgrim
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Hello World", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name Hello World
// @namespace http://diveintogreasemonkey.org/download/
// @description example script to alert "Hello world!" on every page
// @include *
// @exclude http://diveintogreasemonkey.org/*
// @exclude http://www.diveintogreasemonkey.org/*
// ==/UserScript==
alert('Hello world!');
正如您所看到的,这个“Hello World”脚本的大部分都是注释。 有些注释,比如如何安装它的介绍,没有特殊的含义, 它们只是对非专业人士的一些指导。 但是,在所有注释中,有一节有特殊的含义,您将在下一节看到具体的解释。
要看到脚本的效果,您首先要安装它,然后访问一个不属于 diveintogreasemonkey.org 域的网页(例如Google (http://www.google.com/))。这个页面将会像平时一样显示出来,但会弹出一个对话框,写着“Hello world!”
[编辑]
下载
- helloworld.user.js (http://diveintogreasemonkey.org/download/helloworld.user.js)
![[首页]](/stylesheets/images/wiki.png)