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

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

问题描述

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

我已经阅读了文档,但仍然不知道如何在沙盒中再次运行GS脚本;唯一的选择似乎是授予对GS API的访问权限,或者将其授予none,并在没有任何安全性限制的情况下运行该脚本,这在我设计了几十个GS脚本运行时根本不起作用有安全限制,就像这样。

解决方案

Greasemonkey 1.0,从根本上改变了沙箱的工作方式,破坏了成千上万的脚本。这是一个很大的问题,我希望你能和我一起在这个问题的原理错误报告中表达你的意见/经验



Greasemonkey博客声称你可以用下面的方法解决这个问题
$ b $ $ $ $ $ $ $ this.jQuery = jQuery.noConflict(true);

...我不知道哪种情况都可以。但是我不会去测试它,因为这是一个避免副作用的确切的错误方法,所以我们可以使用 DRY-principle <原子编码哲学。在我看来,最好的策略是恢复沙盒,这是迄今为止我已经成功完成的104个脚本。



重新激活通过指定一个 @grant 值(除了 none )以外的沙箱。编辑您的 元数据块以结束以下行

// @grant GM_addStyle
// == / UserScript ==
/ * - @grant指令是需要解决GM 1.0中引入的设计变更,
恢复沙箱。
* /

沙盒将被恢复,所有冲突都将被解决。






您也可以考虑切换到 Scriptish ,它在过去提供了卓越的功能和性能,并且不会受到这种新的沙箱行为的影响。


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.

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, 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.

The Greasemonkey blog claims that you can workaround the issue with the following:

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

... Which I'm not sure will work in all cases. But I'm not going to test it, since 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, this is what I have successfully done with 104 scripts so far.

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

// @grant       GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change introduced in GM 1.0,
    It restores the sandbox.
*/

The sandbox will be restored and all conflicts will be resolved.


You might also consider switching to Scriptish, which has offered superior features and performance in the past, and does not suffer from this new sandbox behavior.

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

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