Greasemonkey 是否允许通过@require 加载本地 javascript?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13883610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does Greasemonkey allow loading local javascript via @require?
提问by vfclists
I have tried to include some local Javascript (in the same folder as the GM script) and in both cases, the script fails to load and the scripts seems to stop working until I restart the browser even if the line with the @require is removed.
我试图包含一些本地 Javascript(与 GM 脚本在同一文件夹中),在这两种情况下,脚本都无法加载并且脚本似乎停止工作,直到我重新启动浏览器,即使删除了带有 @require 的行.
I tried both
我都试过了
// @require file://script.js
then
然后
// @require file:///full/path/to/script.js
and both options don't work.
并且这两个选项都不起作用。
Is loading local Javascript banned in Greasemonkey or does it require some extra settings to enable it?
在 Greasemonkey 中是否禁止加载本地 Javascript 或者是否需要一些额外的设置才能启用它?
回答by Brock Adams
Yes, you can @require
and @resource
local files, but the syntax has to be correct. Also, if the script is installed off a server and trying to @require
a local file, then extensions.greasemonkey.fileIsGreaseable
must be set to true
in about:config.
是的,你可以@require
和@resource
本地文件,但语法必须是正确的。此外,如果脚本安装在服务器上并尝试@require
本地文件,则extensions.greasemonkey.fileIsGreaseable
必须true
在about:config 中设置。
For JS in the same folderas the script:
对于与脚本位于同一文件夹中的JS :
// @require Local_Require_1.js
Or use a relative path:
或者使用相对路径:
// @require resources/Local_Require_2.js
A full path:
一个完整的路径:
// @require file:///D:/Local_Require_3.js
Don't forget the drive letter on Windows.
不要忘记 Windows 上的驱动器号。
Note that any or all parts of the @require
directive can be case-sensitive, depending on your OS. So, match case exactly.
请注意,@require
指令的任何或所有部分都可以区分大小写,具体取决于您的操作系统。所以,完全匹配大小写。
Also note that when live-editing a script, especially changing @require
directives, the script may sometimes silently stop working. If that happens, close the target page tab, uninstall and reinstall the script.
另请注意,在实时编辑脚本时,尤其是更改@require
指令时,脚本有时可能会静默停止工作。如果发生这种情况,请关闭目标页面选项卡,卸载并重新安装脚本。