javascript - Greasemonkey Jquery 干扰?

标签 javascript jquery greasemonkey

<分区>

Possible Duplicate:
jQuery in Greasemonkey 1.0 conflicts with websites using jQuery

看来,如果我的任何 greasemonkey 脚本具有如下所示的行,我就会在包含 jquery 的站点上收到错误。我不确定为什么,但我确实注意到一些 javascript 事件完全没有触发。 (例如在 SO 上我不能添加评论)。

我可以在脚本中排除 SO 但有更好的解决方案吗?也许我应该在测试 jquery 是否存在后动态添加 jquery。我该如何解决这个问题以及如何在不使用 jquery 的情况下将 jquery 脚本标签添加到正文中?

// @require         http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js

最佳答案

Greasemonkey 1.0, radically changed the way the sandbox works ,破坏了数千个脚本。另见,jQuery in Greasemonkey 1.0 conflicts with websites using jQuery .

这是一个大问题,Greasemonkey 的主要开发人员表示完全不愿意以明智的方式解决它。

要解决它,请将沙箱恢复到您的脚本,并通过编辑您的Metadata Block 来解决$ 冲突。以以下几行结尾:

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


指定 @grant 值(none 除外)会重新激活沙箱。


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

Scriptish,到目前为止,还没有发布破坏其大部分安装基础的更新。

关于javascript - Greasemonkey Jquery 干扰?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12983202/

相关文章:

javascript - History.pushState() 导致浏览器导航

javascript - Backbone.js - 在哪里存储状态信息?

jQuery:$(document).ready() 在 IE 中太慢

javascript - 如何让 Greasemonkey 自动点击特定站点上的 "weird"链接?

javascript - 从浏览器控制台访问 Greasemonkey/Tampermonkey 变量?

javascript - 编写这个 JS reduce() 代码的更好方法?

javascript - 页面加载时初始化 "hidden"工具提示

google-chrome - 在 Chrome 中通过用户脚本替换页面功能?

jquery - 在可滚动的 div 中水平拖动表格(或其他内容)

javascript - 如何使用 jQuery 隐藏桌面上的汉堡菜单?