【问题标题】:Can Greasemonkey work with the file:// protocol?Greasemonkey 可以使用 file:// 协议吗?
【发布时间】:2013-11-23 12:05:05
【问题描述】:

我有一个简单的 Greasemonkey 脚本:

// ==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 上运行?

在“用户设置”部分,我将 http://*file://* 作为包含的页面,在“脚本设置”部分,我将 http* file* 在“包含的页面”框中。

【问题讨论】:

    标签: greasemonkey filepath url-scheme


    【解决方案1】:

    "Greaseable schemes" in the Greasemonkey docs。 Greasemonkey 默认忽略file:// 协议。

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

    您可能需要重新启动 Firefox 才能使此设置生效。



    另外,// @include http* file* 是无效的语法。你会使用:

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

    除了,尽量避免使用这样的全局包含。将脚本调整到您明确定位的域和/或页面。

    这:避免意外的副作用,提高性能,并减少被某些“零日”漏洞利用的机会。


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

    【讨论】:

    • 谢谢您,先生。我本来会给你投票的,但我太新了,无法做到这一点。仅供参考,我不必重新启动 Firefox 即可使设置更改生效。
    • 请注意:greasemonkey 中的 http(s) 现在拒绝“文件”
    • @feildmaster,这是 GM 4 的一个缺陷,是几十个之一。这也是通用汽车的首席控制员说要改用 Tampermonkey 或 Violentmonkey 的另一个原因。请注意,greasemonkey-4 是与greasemonkey 分开的标签。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    • 2012-09-01
    • 2021-01-06
    • 1970-01-01
    • 2018-10-30
    • 2011-09-12
    • 2021-04-22
    相关资源
    最近更新 更多