为什么 jQuery “nth-child” 选择器在 GreaseMonkey (0.8) 中不起作用?
我相信 jQuery 的 :nth-child 选择器在 GreaseMonkey 0.8 中不起作用。 (底部是一个快速 GM 脚本来测试这一点。) 为什么是这样? 这是在 GreaseMonkey 中工作的已知限制吗? 任何人都可以推荐解决这个问题的方法吗?
另外,为什么一些(绝对不是全部)jQuery 查询在 GreaseMonkey 中运行慢得多,我现在没有快速基准测试,但我已经当我构建一个非常复杂的 GM 脚本,严重依赖 GM 时,经常注意到它< /a>. 我会在 GM 外部的 Firebug 中运行我的代码,事情会很快,而在 GM 内部,浏览器就会崩溃。 我知道这很模糊,但我想知道 GM 或 jQuery 中是否存在一些广泛的架构原因,为什么会出现这种情况。
谢谢!
// ==UserScript==
// @name Test of nth-child
// @namespace http://elzr.com
// @description nth-child doesn't work in jQuery within GreaseMonkey
// @include http://en.wikipedia.org/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
// @author Eliazar Parra elzr.com
// ==/UserScript==
//
// For detailed info and screenshots see http://elzr.com/posts/wikipedia-backbars
$(document).ready(function() {
console.log($('a:nth-child(1)').length)
});
I believe jQuery's :nth-child selector doesn't work inside GreaseMonkey 0.8.
(At the bottom is a quick GM script to test this.)
Why is this?
Is this a known limitation from working inside GreaseMonkey?
Can anyone recommend a way around this?
Also, why is it that some (definitely not all) jQuery queries run much slower inside GreaseMonkey, I don't have a quick benchmark test right now, but I've noticed it often as I was building a pretty complex GM script that relied heavily in GM. I would run my code outside GM, in Firebug, and things would be snappy, while inside GM the browser was brought to its knees. I know that's vague but I was wondering if there are some broad architectural reasons in GM or jQuery why this would be the case.
Thanks!
// ==UserScript==
// @name Test of nth-child
// @namespace http://elzr.com
// @description nth-child doesn't work in jQuery within GreaseMonkey
// @include http://en.wikipedia.org/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
// @author Eliazar Parra elzr.com
// ==/UserScript==
//
// For detailed info and screenshots see http://elzr.com/posts/wikipedia-backbars
$(document).ready(function() {
console.log($('a:nth-child(1)').length)
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能与 GreaseMonkey 如何使用 XPCNativeWrapper 来确保安全有关。 它们肯定会增加开销,并且可能会与 JQuery 发生冲突。
This might be related to how GreaseMonkey uses XPCNativeWrappers for security. They definitely add overhead, and might be bumping up against JQuery.