<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -31,33 +31,29 @@ jQuery(function ($) {
     });
 
     $(window).load(function () {
-        /* I don't know of a better way to trap the gist js than this. Hopefully it
-         * doesn't break anything too badly. By the time this runs document.write
-         * should be pretty much useless anyway */
-        var old_write = document.write;
-
-        document.write = function (html) {
-            if ( html == '&lt;link rel=&quot;stylesheet&quot; href=&quot;http://gist.github.com/stylesheets/gist/embed.css&quot;/&gt;' ) {
-                /* skip the stylesheet */
-            } else if ( html.indexOf('&lt;div id=&quot;gist-') == 0 ) {
-                /* find the fake gist and replace it with this one. */
-                var gist = $(html);
-                var id = gist.attr('id');
-
-                if ( id.indexOf('gist') == 0 )
-                    $('#fake-' + id).replaceWith(gist);
-            } else {
-                /* otherwise proceed normally */
-                old_write.apply(document, arguments);
-            }
-        };
-
         $('div.gist[id]').each(function () {
             var id = $(this).attr('id').match(/\d+/)[0];
 
-            /* asynchronously fetch the gist itself. It will be evaled and the html
-             * will be trapped by the document.write wrapper */
-            $.getScript(&quot;http://gist.github.com/&quot;+ id +&quot;.js&quot;);
+            /* asynchronously fetch the gist data */
+            $.getJSON(&quot;http://gist.github.com/&quot;+ id +&quot;.json?callback=?&quot;, function (gist) {
+                /* Figure out if we need to add the stylesheet
+                 *
+                 * for some reason
+                 * $(&quot;link[rel=stylesheet][href='&quot; + gist.stylehseet + &quot;']&quot;).length == 0
+                 * doesn't work */
+                var add_stylesheet = true;
+                $(&quot;link[rel=stylesheet]&quot;).each(function (i,e) {
+                    if ( $(e).attr('href') == gist.stylesheet )
+                        add_stylesheet = false;
+                });
+
+                /* if the stylesheet is not yet in the document, add it */
+                if ( add_stylesheet )
+                    $(&quot;head&quot;).append('&lt;link rel=&quot;stylesheet&quot; href=&quot;' + gist.stylesheet + '&quot; /&gt;');
+
+                /* find the fake gist and replace it with the marked up one */
+                $('#fake-gist-'+gist.repo).replaceWith(gist.div);
+            });
         });
     });
 });</diff>
      <filename>gist_upgrade.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>07ed5188032c0e6db2b1eecc667240aae6dfb5f6</id>
    </parent>
  </parents>
  <author>
    <name>Yuval Kogman</name>
    <email>nothingmuch@woobling.org</email>
  </author>
  <url>http://github.com/nothingmuch/jquery-gist-upgrade/commit/ed700c66428e0b05df66010c2ba711fafb2cc297</url>
  <id>ed700c66428e0b05df66010c2ba711fafb2cc297</id>
  <committed-date>2009-07-01T15:33:13-07:00</committed-date>
  <authored-date>2009-07-01T15:33:13-07:00</authored-date>
  <message>use the new JSONP api</message>
  <tree>5e47ea000748df32ceef60b2a5c574d647386fd2</tree>
  <committer>
    <name>Yuval Kogman</name>
    <email>nothingmuch@woobling.org</email>
  </committer>
</commit>
