My Greasemonkey scripts all work in Firefox 3.6, but in Chrome 6 nothing special happens when I load a page that is supposed to trigger them. Here's an example script (pasted below) that highlights top comments on Hacker News. Can anyone identify what I'm doing wrong? When I click on the user.js file and install it in Chrome, the installation succeeds.
// ==UserScript==
// @name Hacker News highlight
// @namespace http://news.ycombinator.com
// @description highlights popular comments
// @include http://news.ycombinator.com/item*
// ==/UserScript==
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
// Check if jQuery's loaded
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();
function letsJQuery() {
var maxScore = 0;
var secBest = 0;
var min = 0;
var numComments = 0;
$(".comhead > span").each(function() {
numComments = numComments + 1;
var score = parseInt($(this).text().split(' ')[0]);
if(score > maxScore) {
maxScore = score;
}
else if(score > secBest) {
secBest = score;
}
});
min = maxScore - secBest;
$(".comhead > span").each(function() {
var score = parseInt($(this).text().split(' ')[0]);
if(min!=0 && score >= min + 1) {
$(this).css({'background-color':'#B2D7FB', 'padding':'4px 4px 4px 4px','-moz-border-radius':'3px', '-webkit-border-radius':'3x'});
}
});
}