title: Why is $ undefined when I try to use jQuery in GreaseMonkey?
body: <p>I'm totally new to GreaseMonkey, but I'm trying to make a little script.</p>
  
  <pre><code>// ==UserScript==
  // @require       http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
  // ==/UserScript==
  (function() {
      $ = unsafeWindow.jQuery;
      alert($); // this gives 'undefined'
  }());
  </code></pre>
  
  <p>Why does the alert give <code>undefined</code> and how to fix this?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I tried this:</p>
  
  <pre><code>(function(){
    //boilerplate greasemonkey to wait until jQuery is defined...
    function GM_wait()
    {
      alert('ok');
      if(typeof unsafeWindow.jQuery == 'undefined')
        window.setTimeout(GM_wait,100);
      else
        unsafeWindow.jQuery(function() { letsJQuery(unsafeWindow.jQuery); });
    }
    GM_wait();
  
    function letsJQuery($)
    {
      alert($);
    }
  })(); 
  </code></pre>
  
  <p>but this gave me an infinite loop of ok-alerts. Seems like jQuery doesn't get loaded at all.</p>