views:

570

answers:

1

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)
});
+1  A: 

This might be related to how GreaseMonkey uses XPCNativeWrappers for security. They definitely add overhead, and might be bumping up against JQuery.

rampion