首页 | 最近更改 | 编辑本页 | 较早版本

可打印版 | 免责声明

Not logged in
登录 | 帮助
 

Firefox:Dive Into Greasemonkey/2.1. Hello World

Mozilla中文Wiki

您的位置:Dive Into Greasemonkey您的第一个用户脚本Hello World

2.1. Hello World

我们步入 Greasemonkey 美妙世界的万里长征将从第一步开始, 所有读过技术手册的读者都会很熟悉这一步:让您的电脑打出“Hello world”。

Image:Permalink.gif 例子: 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!”


下载


← 您的第一个用户脚本
用元数据描述您的用户脚本 →

取自"http://wiki.mozcn.org/index.php/Firefox:Dive_Into_Greasemonkey/2.1._Hello_World"

本页面已经被浏览3509次。 最后更改03:32 2006年9月18日. 本站内容在创作共用署名-非商业用途-保持一致条款下发布。


[首页]
首页
最近更改
随机页面
新闻动态

编辑本页
讨论本页
较早版本
链入页面
链出更改

特殊页面
错误报告