title: Append script to body, using Chrome user script
body: <p>I want to add a script to a given page with a Greasemonkey style user script in Chrome.</p>
  
  <p>I use this <a href="http://erikvold.com/blog/index.cfm/2010/6/14/using-jquery-with-a-user-script" rel="nofollow">trick</a> to add jQuery to my user script.</p>
  
  <p>If I try to add i.e. <code>&lt;h1&gt;Test&lt;/h1&gt;</code> to a pages body with jQuery's append-method, everything works fine.</p>
  
  <p>However if I try to append a JS-script nothing happens.</p>
  
  <p>How do I troubleshoot a problem like this?</p>
  
  <p>This is my .user.js-file:</p>
  
  <pre><code>// ==UserScript==
  // @match http://*/*
  // ==/UserScript==
  
  // a function that loads jQuery and calls a callback function when jQuery has finished loading
  function addJQuery(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
    script.addEventListener('load', function() {
      var script = document.createElement("script");
      script.textContent = "(" + callback.toString() + ")();";
      document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
  }
  
  // the guts of this userscript
  function main() {
  
  $(document).ready(function() {
      $('body').append('&lt;script type="text/javascript" src="http://timkl.com/wip/bibobRedesign/js/jquery.contenthack.js"&gt;&lt;/script&gt;');
  });
  
  }
  
  // load jQuery and execute the main function
  addJQuery(main);
  </code></pre>