1

我有一个要在每个页面上运行的脚本。要做到这一点很容易,我只需设置@include *并完成。它显示在每个页面上,由我在代码中分配给它的热键组合激活。它按预期工作并且没有问题。

但是,我希望它也可以在空白选项卡上使用。如果您有一个包含实际内容的页面(如果您愿意,可以进行文档分配)它可以正常工作,我想它可以将脚本注入并运行,我明白了。我想知道并希望是否有办法让脚本也钩住空白标签页。

我对此进行了大量研究,但无济于事,我希望我这里的一些对 JS 有更广泛接触的朋友,也许在这方面获得的经验可以提供解决方案。我将不胜感激。

4

1 回答 1

2

See the docs at "Include and exclude rules, Extra schemes". for a script to run on blank tabs, you must now explicitly set @include about:blank.

For example:

// ==UserScript==
// @name        _Very noisy script
// @include     about:blank
// @include     *
// ==/UserScript==

alert ("Fire on blank");

However, Firefox now uses about:newtab by default, and Greasemonkey currently doesn't consider about:newtab to be "Greaseable". (It should though, and I'll look into getting a pull-request accepted for this.)

So, to get scripts firing on blank tabs, you currently must set those blank tabs back to using about:blank.
Do that by opening about:config and setting browser.newtab.url to about:blank.

于 2013-08-23T05:49:06.823 回答