Greasemonkey + jQuery

It used to be difficult to combine Greasemonkey and jQuery (or any other javascript library). Looking into it again, I came across 3 methods and this comment from Stephan Sokolow:

For the record, the newest Greasemonkey versions should now provide a much better alternative to this.

See for an example of how to efficiently load jQuery from the Google AJAX API … at userscript install time via the @require metadata key.

It really is very simple now—an example from the page linked aboved:

// ==UserScript==
// @name          Hello jQuery
// @namespace
// @description   jQuery test script
// @include       *
// @require
// ==/UserScript==

$(document).ready(function() {
	$("a").click(function() {
		alert("Hello world!");

And here’s a script I wrote which takes the top 100 movie torrents from The Pirate Bay and adjusts the size of each link based on its IMDB rating:

before and after comparison of The Pirate Bay

Install the Greasemonkey script and visit The Pirate Bay’s Top 100 Movies page to see it in action. You can also view the source.

This entry was posted in Code and tagged , , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.