A bookmarklet for use with Kindle "Your Highlights" page

I heard Maria Popova's Kindle highlights lament on Tim Ferris's podcast and thought I would try to solve some part of it. Below is a bookmarklet that when used while viewing the highlights page will replace the page with data from the original page and then present in a format and style suitable for copy & pasting into Evernote. It has had VERY limited testing, but perhaps you will find it useful. Note that since this code uses HTML scraping to gather the data any change Amazon.com makes to the format of the original page may adversely affect the bookmarklet's functionality.

javascript:(function(){
var O = $('<div class="books"/>');
var S;
var xs = $("#allHighlightedBooks").children();
for ( var i = 0; i < xs.length; i++ ) {
  var x = $(xs[i]);
  var c = x.attr("class");
  if ( c.indexOf("bookMain") != -1 ) {
    t = $('.title',x).text();
    a = $('.author',x).text();
    l = $('a',x).attr("href");
    b = $('<div class="book"/>').appendTo(O);
    $('<div class="title"/>').text(t).appendTo(b);
    $('<div class="author"/>').text(a).appendTo(b);
    $('<div class="link"><a href="'+l+'">'+l+'</a></div>').appendTo(b);
    S = $('<div class="selections"/>').appendTo(b);
  }
  else if ( c.indexOf("highlightRow") != -1 ) {
    h = $('.highlight',x).text();
    n = $('.noteContent',x).text();
    l = $('.linkOut',x).attr("href");
    x = $('<div class="selection"/>').appendTo(S);
    $('<div class="selection"/>').text(h).appendTo(x);
    $('<div class="note"/>').text(n).appendTo(x);
    $('<div class="link"><a href="'+l+'">'+l+'</a></div>').appendTo(x);
  }
}
$(window.document.head).html(
  '<style>' +
  'div { margin-bottom: 1ex; }' + "\n" +
  '.title { font-weight: bold; }' +
  '</style>'  
);
$(window.document.body).html(O[0].outerHTML);
})();

The following code is also at https://gist.github.com/andrewgilmartin/26fd5b2ce02a3219c96c. Any suggestions on how to better use jQuery are most welcome.