1

我相信 jQuery 的 :nth-child 选择器在 GreaseMonkey 0.8 中不起作用。(底部是一个快速的 GM 脚本来测试它。)这是为什么?这是在 GreaseMonkey 内部工作的已知限制吗?任何人都可以推荐一种解决方法吗?

另外,为什么一些(绝对不是全部)jQuery 查询在 GreaseMonkey 中运行慢得多,我现在没有快速的基准测试,但我经常注意到它,因为我正在构建一个非常复杂的依赖于 GM 脚本重度在通用汽车。我会在 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)
});
4

1 回答 1

1

这可能与 GreaseMonkey 如何使用XPCNativeWrapper来保证安全性有关。它们肯定会增加开销,并且可能会遇到 JQuery。

于 2009-06-12T21:36:42.240 回答