Multiple-dependancy Chrome-friendly userscript pattern

By Brian Schweitzer Last update May 10, 2012 — Installed 614 times.

Script Summary: Chrome- and Firefox-friendly userscript pattern with third-party and external dependency support.

Version: 1.2

This is a userscript pattern to allow writing Chrome- and Firefox-friendly scripts which depend on one or more external scripts. Also included is support for including third-party scripts inside your userscript, but separately from your own code.

  • v1.0.0 2012-01-20: Initial release
  • v1.0.1 2012-01-20: Slightly more efficient version
  • v1.1.0 2012-01-21: Fix a few GM-specific issues that were blocking 100% Firefox-compatability
  • v1.1.1 2012-01-21: Add non-jQuery 3rd party example, notes on use.
  • v1.1.2 2012-01-23: Minor speed and resource utilization improvement.
  • v1.1.3 2012-05-09: jQuery version push.
  • v1.2.0 2012-05-10: Reverse the layout of functions to put non-framework code at the top for easier jshinting. Add strict mode. Fix missing semicolon.

A few important notes:

  1. In Firefox, this breaks out of the GreaseMonkey sandbox. So it's console.log('foo'), not unsafeWindow.console.log('foo').
  2. Any non-jQuery third party code needs to piggyback on jQuery to stay in scope. See the example given. To access sayHellow within your own code (in main), you'd then use $.sayHellow(who), instead of sayHellow(who).