Greasemonkey 1.0 中的 jQuery 与使用 jQuery 的网站发生冲突 [英] jQuery in Greasemonkey 1.0 conflicts with websites using jQuery

查看:25
本文介绍了Greasemonkey 1.0 中的 jQuery 与使用 jQuery 的网站发生冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从几天前发布新的 Greasemonkey 1.0 以来,每个拥有 jQuery 的站点以及我在 Greasemonkey 脚本中使用 jQuery 的地方都无法正确运行我的脚本.我在 GS 脚本中的 jQuery(使用 @require 元数据)与页面的 jQuery 冲突.这是由于新的 @grant 代码.

Ever since the new Greasemonkey 1.0 was released a few days ago, every site that has jQuery and where I use jQuery in my Greasemonkey script do not run my script properly. The jQuery I have in my GS script (using the @require metadata) conflicts with the page's jQuery. This is due to the new @grant code.

我已经阅读了文档,但仍然不知道如何再次在沙箱中运行 GS 脚本;唯一的选择似乎是授予对 GS API 的访问权限或授予任何权限并在没有任何安全限制的情况下运行脚本,当我设计了数十个 GS 脚本以运行时,这对我来说根本不起作用有安全限制,喜欢这种方式.

I've read the documentation but still don't know how to run GS scripts in a sandbox again; the only options seem to be to either grant access to a GS API or to grant it to none and run the script without any security limitations, which doesn't work at all for me when I've designed my dozens of GS scripts to run WITH security limitations and like it that way.

推荐答案

Greasemonkey 1.0,从根本上改变了沙盒工作,破坏了数千个脚本.这是一个很大的问题,我希望你能和我一起就原则发表意见/经验此问题的错误报告.

Greasemonkey 1.0, radically changed the way the sandbox works, busting thousands of scripts. This is a huge problem, and I hope you will join me in voicing your opinion/experiences on the principle bug report for this issue.

Greasemonkey 博客声称您可以解决以下问题:

this.$ = this.jQuery = jQuery.noConflict(true);

...我不确定这在所有情况下都有效.这是避免副作用的完全错误的方法,DRY 原则,原子- 编码哲学.在我的意见中,最好的策略是恢复沙箱.

... Which I'm not sure will work in all cases. And it is the exact wrong approach from a side-effects-avoiding, DRY-principle, atomic-coding philosophy.   In my opinion, the best strategy is to restore the sandbox.

通过指定 @grant 值(none 除外)重新激活沙箱.编辑您的元数据块,以下列行结尾:

Reactivate the sandbox by specifying a @grant value (other than none). Edit your Metadata Block to end with the following lines:

// @grant       GM_addStyle
// @grant       GM.getValue
// ==/UserScript==
/*- The @grant directive is needed to work around a design flaws introduced in GM 1.0
    and again in GM 4.0.
    It restores the sandbox.
*/

将恢复沙箱并解决所有冲突.
并且脚本将与 Tampermonkey 和 Violentmonkey 等高级引擎兼容.

The sandbox will be restored and all conflicts will be resolved.
And the scripts will be compatible with superior engines like Tampermonkey and Violentmonkey.

这篇关于Greasemonkey 1.0 中的 jQuery 与使用 jQuery 的网站发生冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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