用户脚本 Chrome 与 Firefox
我已经为greasemonkey编写了一个大的用户脚本,它在firefox中工作得很好,但在chrome中没有任何反应:(
// ==UserScript==
// @name Name
// @description Desc.
// @author chiefwrigley
// @version 7.3
// @license (CC) chiefwrigley
// @namespace http://userscripts.org/scripts/show/103899
// @include *
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
// ==/UserScript==
我可以使用哪些函数,哪些不能?例如GM_setvalue...是否有相同的函数?
i have written a big userscript for greasemonkey which works just fine in firefox, but in chrome nothing happens :(
// ==UserScript==
// @name Name
// @description Desc.
// @author chiefwrigley
// @version 7.3
// @license (CC) chiefwrigley
// @namespace http://userscripts.org/scripts/show/103899
// @include *
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
// ==/UserScript==
which functions can i use and which not? e.g. GM_setvalue... are there equal functions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用Tampermonkey。它允许几乎所有 GM 脚本在 Chrome 上运行。
对于 Chrome 用户脚本允许的有点过时的矩阵,否则,请从此表(需要更新)开始)。
Use Tampermonkey. It allows almost all GM scripts to run on Chrome.
For a somewhat dated matrix of what Chrome userscripts allow, otherwise, start with this table (which needs updating).
您可以查看 Greasemonkey Wiki 以了解有关跨浏览器兼容性的信息。不过,一个好的经验法则是其他浏览器并不真正支持任何 GM_* 功能。
特别是对于 Chrome,它似乎不支持“@require、@resource、unsafeWindow、GM_registerMenuCommand、GM_setValue 或 GM_getValue”。和“GM_xmlhttpRequest 仅是同源的。” [来源]
You can check out the Greasemonkey Wiki to find out about cross browser compatibility. A good rule of thumb though is that other browsers don't really support any GM_* functionality.
For Chrome specifically, it looks like it doesn't support "@require, @resource, unsafeWindow, GM_registerMenuCommand, GM_setValue, or GM_getValue." and "GM_xmlhttpRequest is same-origin only." [Source]
如果没有发生任何事情,并且您依赖 jQuery,可能的原因是 chrome 不使用 @require,因此 jQuery 不存在...这意味着您的 $(document).ready() 没有执行任何操作,所以脚本永远不会开始。
我编写了一个用户脚本/Greasemonkey 模式,它可以让您在 Chrome 和 FF 以及 Opera 中使用 jQuery(和 UI,以及您需要的任何其他内容)。 http://userscripts.org/scripts/show/123588
If nothing is happening, and you're depending on jQuery, the likely cause is that chrome doesn't use @require, so jQuery isn't present... meaning your $(document).ready() is doing nothing, so the script never starts.
I've written a userscript/Greasemonkey pattern which will let you get jQuery (and UI, and whatever else you need) working, in both Chrome and FF, as well as Opera. http://userscripts.org/scripts/show/123588