jQuery in Greasemonkey 1.0 conflicts with websites using jQuery(Greasemonkey 1.0 中的 jQuery 与使用 jQuery 的网站冲突)
问题描述
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. 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.
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.
*/
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 的网站冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Greasemonkey 1.0 中的 jQuery 与使用 jQuery 的网站冲突


- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01