Greasemonkey可以使用file://协议吗? [英] Can Greasemonkey work with the file:// protocol?

查看:188
本文介绍了Greasemonkey可以使用file://协议吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Greasemonkey脚本:

I have a simple Greasemonkey script:

// ==UserScript== 
// @name hello
// @namespace http://www.webmonkey.com 
// @description A test of accessing documents using file:// protocol
// @include     http* file*
// @grant       none
// ==/UserScript==

alert("hi");

只要URL的格式为http://...,它就可以正常工作.如何使脚本在file://...格式的URL上运行?

It works fine as long as the URL is of the form http://... How do I also get the script to run on URLs of the form file://...?

在用户设置"部分,我将http://*file://*作为包含的页面,在脚本设置"部分中,我将"c4>"包含在包含的页面"框中.

In the User Settings section I have http://* and file://* as the included pages and in the Script Settings section I have http* file* in the "Included Pages" box.

推荐答案

请参阅Greasemonkey文档中的可润滑方案" . Greasemonkey默认情况下会忽略file://协议.

See "Greaseable schemes" in the Greasemonkey docs. Greasemonkey ignores the file:// protocol by default.

要使脚本使用file://路径,您需要打开 about:config 并将extensions.greasemonkey.fileIsGreaseable设置为true.

For scripts to work with file:// paths, you need to open about:config and set extensions.greasemonkey.fileIsGreaseable to true.

您可能必须重新启动Firefox才能使此设置生效.

You might possibly have to restart Firefox for this setting to take effect.

此外,// @include http* file*是无效的语法.您将使用:

Also, // @include http* file* is invalid syntax. You would use:

// @include     http://*
// @include     https://*
// @include     file://*

除外,尽可能避免使用此类全局包含.调整脚本,使其仅显示您明确定位的域和/或页面.

except, avoid using such global includes as much as you can. Tune to the script to just the domain(s) and/or page(s) you explicitly target.

这:避免了意外的副作用,提高了性能,并减少了被零日"漏洞利用的可能性.

This: avoids unexpected side effects, increases performance, and reduces the chances of being pwned by some "zero day" exploit.

我还建议您删除自己编写的脚本的用户设置选项.这只会在以后导致心痛和混乱. ;)仅将脚本的元数据部分用于您控制的脚本.

I also recommend that you delete the User Settings options for scripts you write yourself. This will only lead to heartache and confusion later. ;) Use the metadata section of the script, only, for scripts you control.

这篇关于Greasemonkey可以使用file://协议吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆