greasemonkey

Greasemonkey Hacks/Getting Started

< Greasemonkey Hacks

Greasemonkey Hacks

Foreword

Credits

Preface

Chapter 1: Getting Started

Chapter 2: Linkmania!

Chapter 3: Beautifying the Web

Chapter 4: Web Forms

Chapter 5: Developer Tools

Chapter 6: Search

Chapter 7: Web Mail

Chapter 8: Accessibility

Chapter 9: Taking Back the Browser

Chapter 10: Syndication

Chapter 11: Site Integration

Chapter 12: Those Not Included in This Classification

Colophon

 

Contents [hide]

1 Hacks 1–12: Introduction

2 Install a User Script

2.1 Installing from the Context Menu

2.2 Installing from the Tools Menu

2.3 Editing Greasemonkey's Configuration Files

3 Provide a Default Configuration

3.1 The Code

3.2 Wrapper

3.3 Name

3.4 Namespace

3.5 Description

3.6 URL Directives

4 Master the @include and @exclude Directives

4.1 Matching with or Without the www. Prefix

4.2 Matching All Subdomains of a Site

4.3 Matching Different Top-Level Domains of a Site

4.4 Deciding Between * and http://*

5 Prevent a User Script from Executing

5.1 Disabling a User Script Without Uninstalling It

5.2 Disabling All User Scripts

5.3 Disabling a User Script by Removing All Included Pages

5.4 Disabling a User Script by Excluding All Pages

5.5 Disabling a User Script by Editing config.xml

5.6 Uninstalling a User Script

6 Configure a User Script

6.1 Inline

6.2 During Installation

6.3 After Installation

6.4 Editing Configuration Files

7 Add or Remove Content on a Page

7.1 Adding an Element

7.2 Removing an Element

7.3 Inserting an Element

7.4 Replacing an Element

7.5 Modifying an Element's Attributes

8 Alter a Page's Style

8.1 Adding a Global Style

8.2 Inserting or Removing a Single Style

8.3 Modifying an Element's Style

9 Master XPath Expressions

9.1 Basic Syntax

9.2 Examples

10 Develop a User Script "Live"

10.1 Setting Up File Associations

10.1.1 On Mac OS X.

10.1.2 On Windows.

10.2 The "Live Editing" Development Cycle

11 Debug a User Script

11.1 Check Error Messages

11.2 Log Errors

11.3 Find Page Elements

11.4 Test JavaScript Code Interactively

12 Embed Graphics in a User Script

12.1 The Code

12.2 Running the Hack

13 Avoid Common Pitfalls

13.1 Security Hole #1: Source Code Leakage

13.2 Security Hole #2: API Leakage

13.3 Security Hole #3: Local File Access

13.4 Redesigning from the Ground Up

13.5 Going Deeper

13.6 Pitfall #1: Auto-eval Strings

13.7 Pitfall #2: Event Handlers

13.8 Pitfall #3: Named Forms and Form Elements

13.9 Pitfall #4: Custom Properties

13.10 Pitfall #5: Iterating Collections

13.11 Pitfall #6: scrollIntoView

13.12 Pitfall #7: location

13.13 Pitfall #8: Calling Remote Page Scripts

13.14 Pitfall #9: watch

13.15 Pitfall #10: style

13.16 Conclusion

Hacks 1–12: Introduction

 

The first thing you need to do to get started with Greasemonkey is install it. Open Firefox and go to http://greasemonkey.mozdev.org. Click the Install Greasemonkey link. Firefox will warn you that it prevented this site from installing software, as shown in Figure 1-1.

Figure 1-1. Firefox, requiring you to whitelist sites to install extensions

 

Click the Edit Options button to bring up the Allowed Sites dialog, as shown in Figure 1-2.

Figure 1-2. Allowed Sites dialog

 

Click the Allow button to add the Greasemonkey site to your list of allowed sites; then click OK to dismiss the dialog. Now, click the Install Greasemonkey link again, and Firefox will pop up the Software Installation dialog, as shown in Figure 1-3.

Figure 1-3. Software Installation dialog

 

Click Install Now to begin the installation process. After it downloads, quit Firefox and relaunch it to finish installing Greasemonkey.

Now that that's out of the way, let's get right to it.

Install a User Script

 

Greasemonkey won't do anything until you start installing user scripts to customize specific web pages.

A Greasemonkey user script is a single file, written in JavaScript, that customizes one or more web pages. So, before Greasemonkey can start working for you, you need to install a user script.

Tip

Many user scripts are available at the Greasemo

转载于:https://www.cnblogs.com/zhang-pengcheng/p/4221125.html

通过使用少量的JavaScript脚本,自定义网页显示方式或表现方式。Greasemonkey是Mozilla Firefox的一个附加组件。它让用户安装一些脚本使大部分HTML为主的网页于用户端直接改变得更方便易用。随着Greasemonkey脚本常驻于浏览器,每次随着目的网页打开而自动做修改,使得运行脚本的用户印象深刻地享受其固定便利性。 技术明细: 大部分Greasemonkey用户脚本都是自行撰写,使用对某网站专用的JavaScript代码,通过文档对象模型(DOM)接口对网页内容做操作。userscripts.org维护了个Greasemonkey数据库。该数据库描述哪个网址网页对应到哪个脚本。当用户加载匹配的网页,Greasemonkey便调用相关的脚本,而该脚本便根据脚本内容改变网页的内容。Greasemonkey脚本亦能通过非网域绑定的XMLHTTP要求来查询外部HTTP资源。Greasemonkey亦遵循某用户名.user.js的格式,这让当该特定用户拜访时Greasemonkey可自动侦测并提供安装选项。除了JavaScript代码,Greasemonkey脚本包括有限可选用后数据集。该后数据集描述了脚本名称、脚本描述、网址用来区分同名脚本的地址空间、以及原本该脚本为哪些网址撰写的列表。Greasefire扩展:同Greasemonkey扩展配合使用,自动显示在userscripts.org的脚本库中是否存在可以在当前正在浏览网站上使用的脚本,如果存在Greasemonkey的猴头图标背景就会变为彩色的。右键点击猴头图标,最上面一行就是打开当前网站可用脚本列表的选项。Platypus(platypus.mozdev.org)附加组件可让用户可以编辑网页(删除或者移动某碍眼的部分)。Platypus随后将结果存成常驻的Greasemonkey脚本。 典型的脚本: 用户群已发展大量的脚本,以下是其中的一些应用:调整Gmail让Google Reader内嵌,因而提供RSS新闻订阅的选项。当联机浏览某本书时同时显示对手网站同本书价钱。去除来自某些站的广告,包括弹出视窗与Google文字广告。改变网页的版面,包括原本该网页作者未考虑到的元素大小与浏览器画面大小。自动完成窗体。浏览某些布告栏网站自动过滤特定的发帖人。增删网页上的某些功能。让用户从某些视频站点如Google Video以及YouTube存下FLV视频文件。从现行网页找寻任何RSS新闻订阅,并将它们显示在可扩展、漂浮于网页上的皮肤里。突破百度贴吧对言论内容的管制,辅助发表繁体汉字及不受贴吧服务器支持的字符,或者将文字转换为图片发表。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值